最好用command来更新数据库,不要用数据集直接更新
解决方案 »
- C#外网远程连接数据库
- 如何从XtraGrid中获取一列数据绑定到c1Chart中.在线等大侠
- 学习serialport中,用vs2008的C#写了一些代码,总提示“未处理InvalidOperationException”端口被关闭
- VS2003启动时出现“Microsoft Development Environment 遇到问题需要关闭”,如何解决?
- 谁有C# 操作WORD 域的例子啊
- 要实现类似.net里面的“属性”设置的功能用什么控件?
- 如何匹配其中的内容!我什么每人能回答我啊,这个问题不是很难吧
- **********用过Remotesoft .net explorer的朋友看进来*********************
- socket只能收到一次数据,第二次就没有反应了。求指导!!
- 请教个关于ProgressBar的问题,进度显示不正常
- 怎么用printDocument实现如下格式的打印?有免费的报表工具也行。
- 请教:我通过一个线程动态给DataGrid(WinForm)添加行,行添加后,其滚动条却用不了?
Friend WithEvents Data_con As System.Data.SqlClient.SqlConnection
Friend WithEvents Data_adp As System.Data.SqlClient.SqlDataAdapterData_adp .update(dataset);在事件中就可以了or Data_adp.update(table)
{
//设置查询字符串
string commString="SELECT * From Customers WHERE "+ "ContactName="+"'"+name+"'";
//新建一个SqlCommand对象
SqlCommand comm=new SqlCommand() ;
//设置SqlCommand对象的查询语句
comm.CommandText=commString;
//设置SqlCommand对象的连接
comm.Connection=this.sqlConnection1; //新建一个数据集存贮查询结果
DataSet dataSet2=new DataSet();
//改变数据适配器对象的查询语句
this.sqlDataAdapter1.SelectCommand=comm;
//填充数据集
this.sqlDataAdapter1.Fill(dataSet2,"Customers"); //具体对每个控件进行数据绑定
//绑定前要清空以前的绑定
this.textBox1.DataBindings.Clear();
this.textBox1.DataBindings.Add("Text",dataSet2,"Customers.CustomerID");
this.textBox2.DataBindings.Clear();
this.textBox2.DataBindings.Add("Text",dataSet2,"Customers.CompanyName");
this.textBox3.DataBindings.Clear();
this.textBox3.DataBindings.Add("Text",dataSet2,"Customers.ContactName");
this.textBox4.DataBindings.Clear();
this.textBox4.DataBindings.Add("Text",dataSet2,"Customers.ContactTitle");
this.textBox5.DataBindings.Clear();
this.textBox5.DataBindings.Add("Text",dataSet2,"Customers.Address");
this.textBox6.DataBindings.Clear();
this.textBox6.DataBindings.Add("Text",dataSet2,"Customers.City");
this.textBox7.DataBindings.Clear();
this.textBox7.DataBindings.Add("Text",dataSet2,"Customers.Region");
this.textBox8.DataBindings.Clear();
this.textBox8.DataBindings.Add("Text",dataSet2,"Customers.PostalCode");
this.textBox9.DataBindings.Clear();
this.textBox9.DataBindings.Add("Text",dataSet2,"Customers.Country");
this.textBox10.DataBindings.Clear();
this.textBox10.DataBindings.Add("Text",dataSet2,"Customers.Phone");
this.textBox11.DataBindings.Clear();
this.textBox11.DataBindings.Add("Text",dataSet2,"Customers.Fax");
}
DataAdapter.update(DataSet, "Table1")
就全部OK了。
根据我用vb的经验,把datagrid的属性
设置成:
allowupdate=true
应该就可以
至于c#嘛,就看其中的表现形式了