LoadDataRow giving constraint error on primary key

H

Heinz Kiosk

I am trying to update a DataTable using LoadDataRow.

Sometimes I reload records that I have read before.

According to the documentation LoadDataRow handles this automatically if the
primary key on the incoming row is the same as a row already in the
DataTable. But I am finding that I get a constraint error when I try it,
along the lines that I am duplicating a unique column. And the constraint
error is on the primary key column. Isn't this what LoadDataRow is supposed
to handle for me? What am I missing?

Thank You

Tom
 
R

Ravi[MSFT]

LoadDataRow in V1.x always does a PK match with "original" values. This can
be the reason why you might see ConstraintException.

There can be two possibilities why you might see the constraint exception:

a) When you've rows in added state in the dataset, you need to be aware of
that added rows only have "Current version" and do not have "Original
version" values. So the incoming values do not match the PK row, so the
LoadDataRow tries to add a new datarow with the same current PK value which
already exists in the dataset.

b) When you've rows in modified state with the original PK value different
from current PK value, and if the incoming value does not match on "Original
version" but matches on "Current version" then LoadDataRow might try to
insert a new row with the current PK value which already exists in the
dataset.

Case a) is a more frequent scenario and it might be the case in your app.
Case b) is less frequent as PK values are not normally modified. The
original version and the current version of the PK values in most of the
cases match and hence it is less frequent to encounter this case.

HTH,
Ravi
 

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