By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,667 Members | 2,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,667 IT Pros & Developers. It's quick & easy.

Updated dataset back to the database

P: n/a
Roy
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
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Roy" <Ro*@discussions.microsoft.com> wrote in message
news:BE**********************************@microsof t.com...
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

Jul 21 '05 #2

P: n/a
Roy

"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
"W.G. Ryan eMVP" wrote:
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

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Roy" <Ro*@discussions.microsoft.com> wrote in message
news:BE**********************************@microsof t.com...
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


Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.