2011-07-28 79 views
0

我想更新我的一个DataSet的内容数据库,但目前我无法用下面的代码可以这样做:如何使用DataSet更新数据库?

string s = "Select number,name from table where id = 5 and num = 20"; 

SqlDataAdapter adapter = new SqlDataAdapter(s, con); 
adapter.Fill(dset, "ABC"); 

SqlCommandBuilder sT = new SqlCommandBuilder(adapter); 
adapter.Update(dset,"ABC"); 

此代码是不是在数据库中更新的ABC表。

+0

你为什么不尝试http://www.google.com/search?q=How+do+I+update+a+database+using+a+DataSet – Jeyara

回答

1

我发现(与相关的OleDbCommandBuilder)尽管MSDN文档将告诉您,您需要手动设置适配器的InsertCommand,UpdateCommand和DeleteCommand以便能够使用这些。

 // a is the adapter 
     // cb is the commandbuilder 
     a.InsertCommand = cb.GetInsertCommand(); 
     a.DeleteCommand = cb.GetDeleteCommand(); 
     a.UpdateCommand = cb.GetUpdateCommand(); 
+0

这个helped.thank你 – laila