Breaking News

Sunday, September 28, 2008

Error: Update requires a valid UpdateCommand when passed DataRow collection with modified rows

Following locs throw an Invalid Operation exception.

OdbcDataAdapter theAdapter = new OdbcDataAdapter(DbCommand);
DataTable dtTable = new DataTable();
int nRecords = theAdapter.Fill(dtTable);
dtTable.Rows[0]["Name"] = "Jackie";
theAdapter.Update(dtTable); //Error!


Error: "Update requires a valid UpdateCommand when passed DataRow collection with modified rows."


Resolution is to add a OdbCommandBuilder, see following locs:

OdbcCommandBuilder theCommand = new OdbcCommandBuilder(theAdapter);
theAdapter.UpdateCommand = theCommand.GetUpdateCommand();



So, the udpated code looks like:

OdbcDataAdapter theAdapter = new OdbcDataAdapter(DbCommand);
DataTable dtTable = new DataTable();
int nRecords = theAdapter.Fill(dtTable);

OdbcCommandBuilder theCommand = new OdbcCommandBuilder(theAdapter);
theAdapter.UpdateCommand = theCommand.GetUpdateCommand();

dtTable.Rows[0]["Name"] = "Jackie";

nRecords = theAdapter.Update(dtAccounts);

1 comment:

  1. Biztalk server online training - 21st Century Software Solutions
    http://www.21cssindia.com/courses/biztalk-server-online-training-213.html
    ఈ పేజీని అనువదించు
    biztalk server online training, biztalk server training, biztalk server online training visakhapatnam, biztalk 2010 online training, microsoft biztalk online training, ...
    మీరు ఈ పేజీని 2 సార్లు సందర్శించారు. చివరగా సందర్శించినది: 9/2/14
    Biztalk admin online training - 21st Century Software Solutions
    http://www.21cssindia.com/courses/biztalk-admin-online-training-220.html
    ఈ పేజీని అనువదించు
    biztalk admin online training, biztalk admin training, biztalk server online training, biztalk server training, biztalk admin course contents, biztalk admin enquiry, ...Courses at 21st Century Software Solutions
    Talend Online Training -Hyperion Online Training - IBM Unica Online Training -
    Siteminder Online Training - SharePoint Online Training - Informatica Online Training
    SalesForce Online Training - Many more… | Call Us +917386622889
    Visit: http://www.21cssindia.com/courses.html

    ReplyDelete

Designed By Published.. Blogger Templates