Home All Groups Group Topic Archive Search About

Writing data back to a database

Author
24 Dec 2005 1:53 PM
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.

Author
24 Dec 2005 5:13 PM
Brock Allen
Look into the SqlDataAdapter and its Update method.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Show quote
> 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.
>
Author
27 Dec 2005 8:25 AM
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.

Show quote
"Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message
news:b8743b115f44f8c7d69a9b113d70@msnews.microsoft.com...
> Look into the SqlDataAdapter and its Update method.
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>> 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.
>>
>
>
Author
28 Dec 2005 2:45 AM
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.

--
Cindy Winegarden  MSCD, Microsoft Visual FoxPro MVP
cindy_winegar***@msn.com  www.cindywinegarden.com


Show quote
"Andrew Chalk" <ach***@magnacartasoftware.com> wrote in message
news:uc9enFJCGHA.3292@TK2MSFTNGP09.phx.gbl...
>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().
Author
28 Dec 2005 3:50 AM
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.

Show quote
"Cindy Winegarden" <cindy_winegar***@msn.com> wrote in message
news:uQYbD91CGHA.2320@TK2MSFTNGP12.phx.gbl...
> 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.
>
> --
> Cindy Winegarden  MSCD, Microsoft Visual FoxPro MVP
> cindy_winegar***@msn.com  www.cindywinegarden.com
>
>
> "Andrew Chalk" <ach***@magnacartasoftware.com> wrote in message
> news:uc9enFJCGHA.3292@TK2MSFTNGP09.phx.gbl...
>>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().
>
>

AddThis Social Bookmark Button