data adapter update using datatable that has MANY changes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi.

I magine that I have a listbox that is bound to a data table.
This means that there is the possiblity that the data table will have
new rows, edited rows, and/or deleted rows.

After everything is done, I would like, at the push of a button, to
update the database with the change(s) made to the data table
via the data adapter's update() method.

However, when I call the update() method, I get an exception error
telling me that the InsertCommand, UpdateCommand, or DeleteComand
has not been set.

My problem is, if I set the said properties, I do not have the necessary
values
to pass to the commands (e.g. values for new rows).

How do I do this all at once?


Thank you
 
thank you Cor, but I'm trying to avoid using this class as advised by most
references.
Anyway, I have solved my problem regarding update() method in general now (I
just had not correctly set the Insert and Delete commands with their
respective parameter values and source column).

I have a new problem now regarding the update command but I'll post that as
another thread.

Thanks again.
 
The Update() method will iterate over the new/modified/deleted DataRows,
copy values from the DataRow to the appropriate input parameters on the
command, execute the appropriate insert/update/delete command, copy output
parameter values back to the DataRow.

the IDataParameter.SourceColumn property tells us for which column on the
DataRow to push/pull the value.
the IDataParameter.SourceVersion property tells us for modified rows, to use
the original value or the new value, i.e original values go in the where
clause and new values go in the set clause.

You can also listen to the RowUpdating and RowUpdated events to see the
command that will be executed. If you want, these are the times you can
manually copy values between the DataRow and command.

-Mark
 
Back
Top