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

    Question

  •  

    When I modify a database record using a text box on my form, and then click the button I placed on the form to update the database record I get an error sometimes. Here is the code lne and error I get:

     

    customerTableAdapter1.Update(myDatabaseDataSet1.Customer);  , <= this is what I run

     

    "Update requires a valid UpdateCommand when passed DataRow collection with modified rows." , <= error message

     

    The weird thing is the code snippet is correct, it is something else in my settings somewhere causing this error, either in the DB or a property setting of one of my controls I guess????

     

    The lesson I am re-creating which provides this code example works fine when I run it from their provided example file (from the lessons downloadable project code) but when I code it all up myself, sometimes I get it right, sometimes I get this error. I just dont know where I am going wrong?

     

    Matt

    Tuesday, October 30, 2007 7:17 PM

Answers

  • Hi Matt,

     

    Thanks for your update.

     

    My suggestion for you is to check if you generate the correct update command for the TableAdapter through the Configuration Wizard when creating a typed DataSet. You can try to check it according to the following steps:

    Double click the DataSet.xsd to open the DataSet designer view ->Right mouse click the TableAdapter and choose "Configure" -> Click "Next" -> Check "Creates methods to send updates directly to the database"

    There is another option for you is to check if the update command is correct through the DataSet.Designer.cs file.

    Besides, you can try to check out this document about how to create TableAdapter queries for reference - http://msdn2.microsoft.com/en-us/library/kda44dwy(VS.80).aspx 

     

    Hope this helps,

    Regards,

    Friday, November 02, 2007 8:54 AM

All replies

  • Hi Matt,

     

    From your exception message saying "Update requires a valid UpdateCommand when passed DataRow collection with modified rows.", it seems that you didn't specify a update command for the table you would like to update using TableAdapter. Try to check if you have a update query in your TableAdapter designer view. Try to check out this MSDN docuemnt about "how to update a database record using TableAdapter" -  http://msdn2.microsoft.com/en-us/library/ms233819(VS.80).aspx

     

    Hope this helps,

    Regards,

    Thursday, November 01, 2007 3:52 AM
  • Hi, thanks for the reply. The strang thing is I DO update the tableadapter per my initial post, unless you are talking about something else I'm not familiar with?

     

    This is what is erroring:

     

    customerTableAdapter1.Update(myDatabaseDataSet1.Customer);  , <= this is what I run, which uses Update()

     

     

    I make sure the names are correct of the objects tied to the form in regards to the database (customerTableAdapter vs. customerTableAdapter1), etc. I dont know what else to do?

     

    Matt

    Thursday, November 01, 2007 5:36 PM
  • Hi Matt,

     

    Thanks for your update.

     

    My suggestion for you is to check if you generate the correct update command for the TableAdapter through the Configuration Wizard when creating a typed DataSet. You can try to check it according to the following steps:

    Double click the DataSet.xsd to open the DataSet designer view ->Right mouse click the TableAdapter and choose "Configure" -> Click "Next" -> Check "Creates methods to send updates directly to the database"

    There is another option for you is to check if the update command is correct through the DataSet.Designer.cs file.

    Besides, you can try to check out this document about how to create TableAdapter queries for reference - http://msdn2.microsoft.com/en-us/library/kda44dwy(VS.80).aspx 

     

    Hope this helps,

    Regards,

    Friday, November 02, 2007 8:54 AM
  •  

    Hi, I really appreciate you taking the time to offer those helpful sugestions. I'll give them a shot now, I'll let you know what happens either way.

     

    Thanks Again,

    Matt

    Friday, November 02, 2007 6:02 PM
  •  

    For some reason, I can't make it produce the error anymore, so I cant test those suggestions at the moment. I guess thats good news, but I'll keep your post in mind for the next time it happens. I'l try to detail what I did incrrectly once I figure it out when it happens again so other newbies like myself might be able to learn from it.

     

    Thanks again for your help,

    Matt

    Friday, November 02, 2007 7:17 PM