Updating Database using DataAdapter.Update command

Itchyo

New member
Joined
Mar 16, 2010
Messages
4
Programming Experience
1-3
Hi,
I'm trying to update my database from my datagrid, the user inputs the data at run time into the datagrid.

I have a button (Add) to update the database and i'm trying to use the command
DishDA.update(DishDS,"Dishes")

However, i keep getting this error
"Update requires a valid InsertCommand when passed DataRow collection with new rows."



Any help will be very much appreciated. Thanks
 
The DataAdapter needs the SQL command to be run when Inserting data. Providing the command to the DataAdapter's InsertCommand property will fix this.

You can also use a SqlCommandBuilder to create the commands.

Hand typed so there may be minor syntax errors.

VB.NET:
Dim scb As SqlCommandBuilder = New SqlCommandBuilder(DishDA)
da.InsertCommand = scb.GetInsertCommand()
da.UpdateCommand = scbGetUpdateCommand)
da.DeleteCommand = scb.GetDeleteCommand()
 
The DataAdapter needs the SQL command to be run when Inserting data. Providing the command to the DataAdapter's InsertCommand property will fix this.

You can also use a SqlCommandBuilder to create the commands.

Hand typed so there may be minor syntax errors.

VB.NET:
Dim scb As SqlCommandBuilder = New SqlCommandBuilder(DishDA)
da.InsertCommand = scb.GetInsertCommand()
da.UpdateCommand = scbGetUpdateCommand)
da.DeleteCommand = scb.GetDeleteCommand()
Lines 2 to 4 of that code are redundant. All you need to do is create the CommandBuilder and that's it. You only need to call GetInsertCommand if you actually intend to make changes to the generated Command, e.g. set its Transaction property.
 
Back
Top