Updating SQL database from a Dataset object

  • Thread starter Thread starter Herb Stull
  • Start date Start date
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
 
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.
 
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
 
Back
Top