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 に答える