开发者

How do I update a database using a DataSet?

开发者 https://www.devze.com 2023-03-23 20:31 出处:网络
I am trying to update my database with the contents of a DataSet, but currently am unable to do so with the following code:

I am trying to update my database with the contents of a DataSet, but currently am unable to do so with the following code:

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

SqlDataAdapt开发者_运维百科er adapter = new SqlDataAdapter(s, con);
adapter.Fill(dset, "ABC");

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

This code is not updating the ABC table in the database.


I've found (with the related OleDbCommandBuilder) that despite what the MSDN documention will tell you, you need to manually set the adapter's InsertCommand, UpdateCommand, and DeleteCommand to be able to use those.

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

精彩评论

暂无评论...
验证码 换一张
取 消