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

  • Thread starter Thread starter Oriane
  • Start date Start date
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
 
Back
Top