Updating SQL database from a Dataset object

H

Herb Stull

Hello All,

I've been looking everywhere for sample code that shows
the proper procedure for updating a SQL database from
results stored in an ADO Dataset.

There are plenty of examples for filling the Dataset, but
none that show all of the code for performing the update
once changes have been made to rows in the Dataset.

I tried using the CommandBuilder and it defines all of
the objects but does not show the code for executing the
update. Ideally I'd like to have a CommandButton on a
form that has On_Click event code that does the update.

I'd really appreciate someone pointing me to such code or
just returning a sample of their own code to accomplish
this.

Thank you, Herb
 
S

Steven Bras [MS]

It should be a simple matter, once you've set up the commands using the
CommandBuilder, of calling the Update method of the DataAdapter, passing in
the Dataset object:

oMyDataAdapter.Update(oMyDataset)

Hope this helps!

Steven Bras, MCSD
Microsoft Developer Support/Data Access Technologies

This posting is provided "AS IS" with no warranties, and confers no rights.

Microsoft Security Announcement: Have you installed the patch for Microsoft
Security Bulletin MS03-026?  If not Microsoft strongly advises you to
review the information at the following link regarding Microsoft Security
Bulletin MS03-026
http://www.microsoft.com/security/security_bulletins/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026.
 
W

William Ryan

As long as your table is Keyed...the commandbuilder will generate update
logic for you. If you have a commandbuilder named myCommandBuilder

you can get the respective commands by doing the following:

Dim mySelect as String = myCommandBuilder.GetSelectCommand().CommandText
Dim myUpdate as String = myCommandBuilder.GetUpdateCommand().CommandText
etc.

You can call update from behind a button or wherever else you choose.

Here's an article by one of the true ADO.NET gurus that you'll definitely
find helpful.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadonet/ht
ml/commandbuilder.asp

Cheers,

Bill
 

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