Dataadapter Add vs Update

G

Guest

I have a generic question regarding ADO.net and how the CommandBuilder works.

I have a datagrid/dataset that is partially populated from pre exisiting records in a database table as well as NEW records/rows which are being added to the same dataset by a user via a simple textbox/form.

My question is, when the user is done adding new records and hits the final UPDATE button, does the dataadapter automatically know which records in my dataset are UPDATE preexisiting records as well as ADD new records (added manually by the user/form) or do I need to somehow programmatically , iterate through each row of the dataset, determine which rows are ADDS and which rows are UPDATES and then assign the appropriate SQL Sub Call (or if then) to each row in order to update the database table.

Thanks
devon
 
S

Scott M.

Any changes to the DataSet (edits, deletions or additions) are marked. When
you call the Update method of the DataAdapter, all changes are pushed to the
original data source.


Devon Kyle said:
I have a generic question regarding ADO.net and how the CommandBuilder works.

I have a datagrid/dataset that is partially populated from pre exisiting
records in a database table as well as NEW records/rows which are being
added to the same dataset by a user via a simple textbox/form.
My question is, when the user is done adding new records and hits the
final UPDATE button, does the dataadapter automatically know which records
in my dataset are UPDATE preexisiting records as well as ADD new records
(added manually by the user/form) or do I need to somehow programmatically ,
iterate through each row of the dataset, determine which rows are ADDS and
which rows are UPDATES and then assign the appropriate SQL Sub Call (or if
then) to each row in order to update the database table.
 
W

William Ryan eMVP

DataRows have a property named RowState which is Added, Deleted, Modified.
So any action simply changes that. If you call DataTable.Rows.Count for
instance and it's 100, then you call .Delete on each row in the table, the
Count will stilll be 100 (however .Remove will take them out of the
collection). Whereas you'd expect it to be 0, it simply changes the
rowstate - after .AcceptChanges is called, then they are removed.. I
mention this just to illustrate that Rowstate is critical here and it's how
the adapter konws which command to fire against which rows - or ifyou want
to do it manually, you cna do the same.

This should help too http://www.knowdotnet.com/articles/efficient_pt4.html

--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
Devon Kyle said:
I have a generic question regarding ADO.net and how the CommandBuilder works.

I have a datagrid/dataset that is partially populated from pre exisiting
records in a database table as well as NEW records/rows which are being
added to the same dataset by a user via a simple textbox/form.
My question is, when the user is done adding new records and hits the
final UPDATE button, does the dataadapter automatically know which records
in my dataset are UPDATE preexisiting records as well as ADD new records
(added manually by the user/form) or do I need to somehow programmatically ,
iterate through each row of the dataset, determine which rows are ADDS and
which rows are UPDATES and then assign the appropriate SQL Sub Call (or if
then) to each row in order to update the database table.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top