CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

求ado.net 2.0的一个实例

楼主longxin123(龙的心)2006-03-04 10:31:10 在 .NET技术 / ASP.NET 提问

求bindingNavigator和textbox绑定的例子,具有增删编辑的功能,谢谢了  
   
  是不是用this.BindingContext[pubsDataSet,   "authors"].AddNew();  
  这个好像是更新不能增加数据呀 问题点数:40、回复次数:6Top

1 楼net_lover(【孟子E章】)回复于 2006-03-04 10:46:53 得分 0

我看了一下  
   
  BindingNavigator   类   属于System.Windows.Forms空间下的,webform可能无法使用  
  Top

2 楼longxin123(龙的心)回复于 2006-03-04 12:31:08 得分 0

那Forms怎么用呀Top

3 楼longxin123(龙的心)回复于 2006-03-04 19:02:28 得分 0

世界第一顶Top

4 楼ghx88(辉)回复于 2006-03-04 20:32:33 得分 0

101个微软提供的Visual   Studio   2005示例  
  http://www.pconline.com.cn/pcedu/empolder/net/0602/762469.htmlTop

5 楼longxin123(龙的心)回复于 2006-03-05 11:06:29 得分 0

using   System;  
  using   System.Collections.Generic;  
  using   System.ComponentModel;  
  using   System.Data;  
  using   System.Data.SqlClient;  
  using   System.Drawing;  
  using   System.Text;  
  using   System.Windows.Forms;  
   
  namespace   UsingBindingNavigator  
  {  
  public   partial   class   Form1   :   Form  
  {  
   
  private   BindingSource   EmployeesBindingSource;  
                  private   System.Windows.Forms.BindingNavigator   BindingNavigatorStandard;  
                  private   System.Windows.Forms.BindingNavigator   BindingNavigatorCustom;  
   
  public   Form1()  
  {  
  InitializeComponent();  
   
  //   Create   a   BindingSource   for   all   the   BindingNavigators   to   use  
  this.EmployeesBindingSource   =   new   BindingSource();  
   
  //   The   first   BindingNavigator   (Toolbox)   was   generated   at   design   time  
  //   by   dragging   the   control   from   the   Toolbox  
  SetupTab2();  
  SetupTab3();  
   
  }  
   
  private   void   Form1_Load(object   sender,   EventArgs   e)  
  {  
  DataSet   ds   =   RetrieveDataSet();  
   
  if   (ds   !=   null)  
  {  
  //   Associate   the   DataSet   with   the   BindingSource.  
  this.EmployeesBindingSource.DataMember   =   "Employee";  
  this.EmployeesBindingSource.DataSource   =   ds;  
   
  //   Associate   the   BindingNavigators   with   the   BindingSource  
  this.EmployeesBindingNavigator.BindingSource   =   this.EmployeesBindingSource;  
  this.BindingNavigatorStandard.BindingSource   =   this.EmployeesBindingSource;  
  this.BindingNavigatorCustom.BindingSource   =   this.EmployeesBindingSource;  
   
  //   Bind   the   form   controls  
  this.employeeIDTextBox.DataBindings.Add(new   System.Windows.Forms.Binding("Text",   this.EmployeesBindingSource,   "EmployeeID",   true));  
  this.titleTextBox.DataBindings.Add(new   System.Windows.Forms.Binding("Text",   this.EmployeesBindingSource,   "Title",   true));  
  this.emergencyContactIDTextBox.DataBindings.Add(new   System.Windows.Forms.Binding("Text",   this.EmployeesBindingSource,   "EmergencyContactID",   true));  
  this.birthDateDateTimePicker.DataBindings.Add(new   System.Windows.Forms.Binding("Value",   this.EmployeesBindingSource,   "BirthDate",   true));  
  this.maritalStatusTextBox.DataBindings.Add(new   System.Windows.Forms.Binding("Text",   this.EmployeesBindingSource,   "MaritalStatus",   true));  
  this.genderTextBox.DataBindings.Add(new   System.Windows.Forms.Binding("Text",   this.EmployeesBindingSource,   "Gender",   true));  
  this.hireDateDateTimePicker.DataBindings.Add(new   System.Windows.Forms.Binding("Value",   this.EmployeesBindingSource,   "HireDate",   true));  
  this.salariedFlagCheckBox.DataBindings.Add(new   System.Windows.Forms.Binding("CheckState",   this.EmployeesBindingSource,   "SalariedFlag",   true));  
  this.baseRateTextBox.DataBindings.Add(new   System.Windows.Forms.Binding("Text",   this.EmployeesBindingSource,   "BaseRate",   true));  
  this.payFrequencyTextBox.DataBindings.Add(new   System.Windows.Forms.Binding("Text",   this.EmployeesBindingSource,   "PayFrequency",   true));  
  this.vacationHoursTextBox.DataBindings.Add(new   System.Windows.Forms.Binding("Text",   this.EmployeesBindingSource,   "VacationHours",   true));  
  this.sickLeaveHoursTextBox.DataBindings.Add(new   System.Windows.Forms.Binding("Text",   this.EmployeesBindingSource,   "SickLeaveHours",   true));  
  this.currentFlagCheckBox.DataBindings.Add(new   System.Windows.Forms.Binding("CheckState",   this.EmployeesBindingSource,   "CurrentFlag",   true));  
  }  
  }  
   
  public   void   SetupTab2()  
  {  
  //   Generate   the   second   BindingNavigator   (Standard   UI)  
  //   Constructor   parameter   addStandardItems   =   true,  
  //   meaning   give   the   control   the   "standard"   VCR   type   UI  
  this.BindingNavigatorStandard   =   new   BindingNavigator(true);  
   
  //   Place   navigator   on   2nd   tab  
  this.tabPageStandard.Controls.Add(this.BindingNavigatorStandard);  
  this.BindingNavigatorStandard.Dock   =   DockStyle.Fill;  
   
  }  
   
  public   void   SetupTab3()  
  {  
  //   Generate   the   third   BindingNavigator   (Custom   UI)  
  //   Constructor   parameter   addStandardItems   =   false,  
  //   for   constructing   a   custom   UI  
  this.BindingNavigatorCustom   =   new   BindingNavigator(false);  
   
  //   Build   the   custom   UI  
  //   Generate   buttons  
  ToolStripButton   firstButton   =   new   ToolStripButton("|<");  
  ToolStripButton   prevButton   =   new   ToolStripButton("<<");  
  ToolStripButton   nextButton   =   new   ToolStripButton(">>");  
  ToolStripButton   lastButton   =   new   ToolStripButton(">|");  
  ToolStripSeparator   separator1   =   new   System.Windows.Forms.ToolStripSeparator();  
  ToolStripTextBox   positionItem   =   new   System.Windows.Forms.ToolStripTextBox();  
  ToolStripLabel   countItem   =   new   System.Windows.Forms.ToolStripLabel();  
  ToolStripSeparator   separator2   =   new   System.Windows.Forms.ToolStripSeparator();  
  ToolStripButton   addNewItem   =   new   System.Windows.Forms.ToolStripButton("Add");  
  ToolStripButton   deleteItem   =   new   System.Windows.Forms.ToolStripButton("Delete");  
   
  positionItem.Text   =   "0";  
  positionItem.ToolTipText   =   "Current   Index";  
   
  //   Add   buttons   to   the   BindingNavigatorCustom,   which   is   a   toolstrip  
  //   The   order   in   which   the   buttons   are   added   is    
  //   the   order   in   which   buttons   are   displayed.  
  this.BindingNavigatorCustom.Items.AddRange(   new   ToolStripItem[]  
  {firstButton,   prevButton,   nextButton,   lastButton,  
  separator1,  
  positionItem,   countItem,  
  separator2,  
  addNewItem,   deleteItem});  
   
  //   Hook   up   controls   to   navigator   functionality  
  this.BindingNavigatorCustom.MoveFirstItem   =   firstButton;  
  this.BindingNavigatorCustom.MoveLastItem   =   lastButton;  
  this.BindingNavigatorCustom.MoveNextItem   =   nextButton;  
  this.BindingNavigatorCustom.MovePreviousItem   =   prevButton;  
  this.BindingNavigatorCustom.PositionItem   =   positionItem;  
  this.BindingNavigatorCustom.CountItem   =   countItem;  
  this.BindingNavigatorCustom.CountItemFormat   =   "of   {0}";  
  this.BindingNavigatorCustom.AddNewItem   =   addNewItem;  
  this.BindingNavigatorCustom.DeleteItem   =   deleteItem;  
  Top

6 楼longxin123(龙的心)回复于 2006-03-05 11:06:47 得分 0

 
  //   Place   navigator   on   3rd   tab  
  this.tabPageCustom.Controls.Add(this.BindingNavigatorCustom);  
  this.BindingNavigatorCustom.Dock   =   DockStyle.Fill;  
   
  }  
   
  public   DataSet   RetrieveDataSet()  
  {  
  try  
  {  
  //   Retrieve   Employee   data   from   database   into   a   DataSet  
  //   Build   a   connnection   string   to   the   database  
  SqlConnectionStringBuilder   connectStringBuilder   =   new   SqlConnectionStringBuilder();  
  connectStringBuilder.DataSource   =   @".\SQLEXPRESS";  
  connectStringBuilder.AttachDBFilename   =   @"C:\Program   Files\Microsoft   SQL   Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf";  
  connectStringBuilder.IntegratedSecurity   =   true;  
  connectStringBuilder.UserInstance   =   true;  
   
  //   Prepare   a   DataSet   to   receive   the   Employee   data  
  DataSet   ds   =   new   DataSet("Employees");  
   
  //   Open   connection   to   the   AdventureWorks   database  
  using   (SqlConnection   connection   =   new   SqlConnection(connectStringBuilder.ConnectionString))  
  {  
  connection.Open();  
  //   Retrieve   Employee   data  
  SqlCommand   command   =   new   SqlCommand(  
  "SELECT   TOP   100   *   FROM   [HumanResources].[Employee]",   connection);  
   
  using   (SqlDataReader   drEmployees   =   command.ExecuteReader())  
  {  
  ds.Load(  
  drEmployees,  
  LoadOption.OverwriteChanges,  
  new   string[]   {   "Employee"   });  
  }  
   
  //   Close   the   connection   to   the   database  
  connection.Close();  
  }  
   
   
  return   ds;  
  }  
  catch   (SqlException   err)  
  {  
  MessageBox.Show(err.Message,   "SQL   Exception",   MessageBoxButtons.OK,   MessageBoxIcon.Error);  
  return   null;  
  }  
  }  
  }  
  }  
   
   
   
   
   
   
   
  ------------------------------------------------------------------------------------  
   
  using   (SqlConnection   connection   =   new   SqlConnection(connectStringBuilder.ConnectionString))  
  {  
  connection.Open();  
  //   Retrieve   Employee   data  
  SqlCommand   command   =   new   SqlCommand(  
  "SELECT   TOP   100   *   FROM   [HumanResources].[Employee]",   connection);  
   
  using   (SqlDataReader   drEmployees   =   command.ExecuteReader())  
  {  
  ds.Load(  
  drEmployees,  
  LoadOption.OverwriteChanges,  
  new   string[]   {   "Employee"   });  
  }  
   
  是什么意思   ???为什么用using    
   
  Top

相关问题

  • 关于ADO类的实例化问题???
  • 谁有.NET RMOTING的实例?
  • 跪求.net水晶报表实例!!!
  • 我的ADO连接怎么不能实例化?
  • 100分求一个ADO访问数据库的简单实例!!!
  • 请问:谁有用ADO连接SQL 2000数据库的实例和资料?
  • 如何使用Ado(不是Ado.net)RecordSet的AddNew(...)函数,请给出实例?
  • 求用文本文件建立ADO的记录集对象的实例
  • 在子线程中创建ADO的实例为什么会出错?
  • 100分求 autodesk volo view control .net实例!急!!!

关键词

  • bindingnavigators
  • form
  • private

得分解答快速导航

  • 帖主:longxin123

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo