S
Stu
This is really more of an SQL question but I'm doing the client-side
coding in C# so I figured it would make sense to post it here.
I'd like to export some portion of data from an SQL database to a
file, then import that data to a different database which has the same
structure. I've googled high and low and come up with a bunch of
different options, all of which seem to be more complicated than I was
hoping this would be.
The most common solution seems to be exporting to XML (easy) and then
using either an updategram or diffgram to import the data (never used
either and they are a little confusing). I need to deal with the
possibility that some rows that are in the exported file already exist
in the database I'm importing into, in which case I would ignore those
rows rather than doing an update. Also I don't fully understand how
to execute a diffgram. The DataSet object has the ability to read/
write a diffgram to/from a file, which seems close to what I want.
However it appears that in order to apply the diffgram to a database
table, I'd have to load the entire table into the DataSet and then do
DataSet.ReadXml(fileName, XmlReadMode.DiffGram) which essentially runs
a Merge. Obviously I don't want to have to load the entire table just
to figure out which IDs not to insert, so is there a better way to do
this that I'm missing? Is it possible to load just the primary keys
of a table into the DataSet and then do ReadXml for the diffgram
against those?
Also if there is a better way other than what I'm trying to do, please
let me know. Thanks in advance, my head is spinning at this point!
coding in C# so I figured it would make sense to post it here.
I'd like to export some portion of data from an SQL database to a
file, then import that data to a different database which has the same
structure. I've googled high and low and come up with a bunch of
different options, all of which seem to be more complicated than I was
hoping this would be.
The most common solution seems to be exporting to XML (easy) and then
using either an updategram or diffgram to import the data (never used
either and they are a little confusing). I need to deal with the
possibility that some rows that are in the exported file already exist
in the database I'm importing into, in which case I would ignore those
rows rather than doing an update. Also I don't fully understand how
to execute a diffgram. The DataSet object has the ability to read/
write a diffgram to/from a file, which seems close to what I want.
However it appears that in order to apply the diffgram to a database
table, I'd have to load the entire table into the DataSet and then do
DataSet.ReadXml(fileName, XmlReadMode.DiffGram) which essentially runs
a Merge. Obviously I don't want to have to load the entire table just
to figure out which IDs not to insert, so is there a better way to do
this that I'm missing? Is it possible to load just the primary keys
of a table into the DataSet and then do ReadXml for the diffgram
against those?
Also if there is a better way other than what I'm trying to do, please
let me know. Thanks in advance, my head is spinning at this point!