Exception: "Update requires a valid InsertCommand..."

Saeros3

Member
Joined
Aug 19, 2009
Messages
9
Programming Experience
1-3
Exception: "Update requires a valid InsertCommand when passed DataRow collection with new rows"
This is the error message i got when i tried to update my database.
The way i'm trying to update is by creating 2 DataRow objects and adding each to a DataTable that i filled with DataAdapters, then i change each column of the new rows to the value of a text box. After that i try to update the DataTables with their respective DataAdapter.

I haven't included any code because there's a lot of code and i'm not sure which parts of it might be relevant. However, if you think you would need to see some of the code, i'll post it.
 
You've added new rows to the DataTable you're saving but the DataAdapter you're using to save it doesn't have any SQL code to INSERT a new record in the database. No database operations can happen without the appropriate SQL code. You can use a CommandBuilder to generate the required SQL, as long as your query involves only one table and returns the primary key, or you can create the InsertCommand yourself.
 
thanks

oh, i see. i'll try using a CommandBuilder then. although it might be interesting to create the InsertCommand myself.
thanks.

Edit:
just to make sure, the insert command would be written something like this, right?:

Dim sqlInsCommand As String = "insert into citylist
(name, state, population, zipcode)
values ('Argos', 'Indiana', '89', '46501');"

DataAdapter.InsertCommand = sqlInsCommand
 
Last edited:
Back
Top