0

我正在尝试使用 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 表。

4

1 回答 1

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();
于 2011-07-28T19:36:51.007 回答