[.NET 2.0]Problem with DataTable.Load (dt,LoadOptions.Upsert)

O

Oriane

Hi,

I would like to update an Sql Server database with Excel data. For this, I
use2 identical typed datatables: dtSql, and dtXls.
Here's my code simplified:

TypedDataTable dtXls = new TypedDataTable;
TypedDataTable dtSql = new TypedDataTable;
dataAdapterXls.Fill (dtXls);
dataAdapterSql.Fill (dtSql);
DataTableReader drXls = dtXls.CreateDataReader();
dtSql.Load(drXls, LoadOption.Upsert);

Some rows in Excel have a primary key (PK1) value that is already present on
the Sql database and therefore in dtSql, and I get this error message on
those rows:
"Column 'PK1'' is constrained to be unique. Value 'xxx'' is already
present."

The documentation states that when using the option "Upsert" of the Load
member : "The incoming values for this row will be written to the current
version of each column. The original version of each column's data will not
be changed."

So to me, those rows should have a current value taken from Excel and a
rowstate equal to "Modified"...

I don't really understand...

Cheers
 

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

Top