Updated dataset back to the database

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

Guest

Hi all,

I've filled a dataset from a select dataadapter. Dataset has been modified
and I need to send changes back to the database. Since dataadapter has been
disposed, what is the code to send these changes to the database.
Thanks,

Roy
 
Roy - the way Updates work is that a given dataadapter loops through each
row of a datatable and checks the rowstate. If none of the rowstates have
changed, nothing happens. But let's say that a Row has been deleted. It
will look to the DeleteCommand for the dataadapter and fire it. The same
process is done for each of the other types of commands - insert and update.

If you want to use DataAdater.Update(DataTable) syntax - then you'll need a
configured adapter - either by creating a new one with those commands
configured correctly or not disposing of the first one and using it again -
but the key is that ANY adapter will work, but it must have each command
configured correctly for each rowstate that you have. So if you have no
Deleted rows, then you don't need a delete command.

The other choice is walking through the datatable yourself, getting the
values that have changed, and calling a ExecuteNonQuery (or one of the other
Executes) to fire the commands one at a time - after all that's all the
adapter is doing for you.

If possible, calling DataAdapter.Update is the cleanest and easiest to
maintain. So even if the adapter is disposed and you can't change that -
you only need the Update, Insert and Delete commands - which you cna feed to
a new adapter and just call .Update.

HTH,

Bill
 
"So even if the adapter is disposed and you can't change that -
you only need the Update, Insert and Delete commands "
Ryan, Would you provide a sample code for this scenario?
Thanks again
Roy
 
Back
Top