Storing Content of a DataSet to a new DB

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello!
I'm storing the results from a SELECT statement in a DataSet.
Now I'd like to INSERT the rows into a different database. (c#)
Can anyone please give me a hint.

Thanks a lot
mrBasti
 
Hi Bastian,

Before filling the dataset, set adapter.AcceptChangesDuringFill = false, so
all the rows are going to be marked as Added.
BTW, there are other, faster, ways of transferring data between databases.
 
Hi Bastian,

Bastian Waidelich said:
Wow that was quick..
Thank you, it almost works like this.
Only: When there are duplicate entries it will throw an exception, but I'd
like to overwrite existing keys. Do you know a solution for this?

You might create a stored procedure on a target server that either inserts
or updates the record.
Or you'll have to load all the existing rows from target server (at least
their keys) so you'll know which rows are for update or insert.
For those for update you'll have to call AcceptChanges() on source row and
then change their field (to the same value) just to make them marked as
Changed.
Could you also say a word about the faster ways, I'm really new to the
business?

Well, Sql server's DTS might be a good choice.
 
Back
Top