Writing data back to a database

A

Andrew Chalk

I have some data in a DataSet and want to write it back to the underlying
SQL Server database. Is there any simple "one-liner" way to write a dataset
back to its database or do I have to go through the steps of creating a
command object, adding parameters and calling ExecuteNonQuery().

Many thanks.
 
A

Andrew Chalk

Thanks. I read that and am now attempting to automatically generate the
update command. I can see that the command is created by examining:
SqlCommand com = cb.GetUpdateCommand();
However changes are still not appearing in the database when I call the
Update() method on the data adaptor instance. Examining the DataAdapter
members I notice that cmdUpdate is 'undefined value'. I have no idea why.
Are their any reasons for this that you can think of?

Many thanks.
 
C

Cindy Winegarden

Hi Andrew,

See if this helps: "How to update a database from a DataSet object by using
Visual Basic .NET" (http://support.microsoft.com/kb/q301248/) . Basically
the procedure is to make the changes you want to the data in the DataSet,
and then pass the Dataset object to the Update method of the DataAdapter
object. You will need to specify the InsertCommand, UpdateCommand, and
DeleteCommand properties of the DataAdapter or you can let VS generate these
for you.
 
A

Andrew Chalk

Thanks. I read about that and am now attempting to automatically generate
the
update command. I can see that the command is created by examining:
SqlCommand com = cb.GetUpdateCommand();
However changes are still not appearing in the database when I call the
Update() method on the data adaptor instance. Examining the DataAdapter
members I notice that cmdUpdate is 'undefined value'. I have no idea why.
Are their any reasons for this that you can think of?

Many thanks.
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top