Home All Groups Group Topic Archive Search About

Insert to DB from Datagrid

Author
13 Mar 2006 9:02 PM
Robert Bevington
Hi everyone,

I have succesfully populated a datagrid with data from an XML file. Now I
want to insert the data into a SQL database table. The database table might
be new and empty, or it might already contain data. What's the best
approach? INSERT To?

Thanx for any pointers in the right direction.

Rob

Author
13 Mar 2006 10:36 PM
W.G. Ryan - MVP
Hi Robert:

If  you have the Diffgram with the XML file (so there's rowstate) then you
can just configure an Adapter with each command you need and point it to the
DB calling update. If you don't have rowstate, you're going to need to loop
through the rows, figure out what actions you want to take, load your params
from the datarow values and then fire an ExecuteNonQuery. If you have the
risk of key voilations then make sure to check If Exists beforehand so you
don't throw unnecessary exceptions.

If I understand the problem correctly, this should do it for you.

Cheers,

Bill
Show quote
"Robert Bevington" <rbeving***@freenet.de> wrote in message
news:eFyh7FuRGHA.3052@TK2MSFTNGP09.phx.gbl...
> Hi everyone,
>
> I have succesfully populated a datagrid with data from an XML file. Now I
> want to insert the data into a SQL database table. The database table
> might be new and empty, or it might already contain data. What's the best
> approach? INSERT To?
>
> Thanx for any pointers in the right direction.
>
> Rob
>
Author
13 Mar 2006 10:51 PM
Elton W
Hi Robert,

If you use ADO.NET 2.0, take look at SqlBulkCopy.WriteToServer.

HTH

Elton Wang

Show quote
"Robert Bevington" wrote:

> Hi everyone,
>
> I have succesfully populated a datagrid with data from an XML file. Now I
> want to insert the data into a SQL database table. The database table might
> be new and empty, or it might already contain data. What's the best
> approach? INSERT To?
>
> Thanx for any pointers in the right direction.
>
> Rob
>
>
>
Author
14 Mar 2006 5:58 AM
Cor Ligthert [MVP]
Robert,

In addition to Elton, have a look at this sample on our website.

http://www.vb-tips.com/default.aspx?ID=65217d17-ac72-44f3-9d35-421ed535c609

I hope this helps,

Cor

Show quote
"Robert Bevington" <rbeving***@freenet.de> schreef in bericht
news:eFyh7FuRGHA.3052@TK2MSFTNGP09.phx.gbl...
> Hi everyone,
>
> I have succesfully populated a datagrid with data from an XML file. Now I
> want to insert the data into a SQL database table. The database table
> might be new and empty, or it might already contain data. What's the best
> approach? INSERT To?
>
> Thanx for any pointers in the right direction.
>
> Rob
>
Author
14 Mar 2006 11:25 PM
Robert Bevington
Thanx guys. I was able to solve my problem using SQLBulkCopy.

Rob
Show quote
"Robert Bevington" <rbeving***@freenet.de> schrieb im Newsbeitrag
news:eFyh7FuRGHA.3052@TK2MSFTNGP09.phx.gbl...
> Hi everyone,
>
> I have succesfully populated a datagrid with data from an XML file. Now I
> want to insert the data into a SQL database table. The database table
> might be new and empty, or it might already contain data. What's the best
> approach? INSERT To?
>
> Thanx for any pointers in the right direction.
>
> Rob
>

AddThis Social Bookmark Button