Merge Failing on Guid Primary Key

B

Brian Korenaga

I'm trying to update a dataset using the GetChanges method, then using
the Merge method to integrate the updated data from the server. The
problem I am having is that when editing row(s) (add/delete is fine),
I am throwing an exception related to the GUID primary key. My
guideline is David Sceppa's ADO .Net book, Chapt. 11.

Per Sceppa's book and the Microsoft docs, the Merge method is supposed
to compare primary keys - if they are identical, the method is
supposed to combine the contents into a single row.

However, when my code gets to the merge statement, I get the following
error:

Additional information: Dataset constraint errors found:
IndividualFromHousehold:Column 'IndividualId' is constrained to be
unique. Value '73875f68-fd9c-4a15-98b9-ed6492c385c4' is already
present.
IndividualFromHousehold:Column 'IndividualId' is constrained to be
unique. Value '73875f68-fd9c-4a15-98b9-ed6492c385c4' is already
present.

When I manually remove the edited row(s) from the original dataset
based on DataViewRowState.ModifiedCurrent, the merge comes off without
a hitch.

Given that PK are SUPPOSED to be unique, does anybody have any ideas
why this isn't working?

Thanks,
Brian
 
M

Miha Markic

Hi Brian,

Two things:
Is the column primary key in datatable?
Why do you need merge - IOW merge is needed only if you read data from
database (example would be an autoincrement field)?
If you don't read anything then just call AcceptChanges on original dataset.
 
B

Brian Korenaga

Hi Brian,

Two things:
Is the column primary key in datatable?
Why do you need merge - IOW merge is needed only if you read data from
database (example would be an autoincrement field)?
If you don't read anything then just call AcceptChanges on original dataset.

Miha,

Thanks for your help. Stupidity is alive and well in my location.
Sure enough a key was set on the guid - unfortunately it was only set
to nullable. I could have sworn I set it to primary key and NOT
nullable (downside of using the IDE?). That will teach me to look at
all the obvious things with extreme care.

In regards to your second question, just for FYI. I need merge
because I am using timestamps for optimistic concurrency and I want
all my guids to come from the server side.

Thanks again for the help.

Brian
 
M

Miha Markic

Thanks for your help. Stupidity is alive and well in my location.
Sure enough a key was set on the guid - unfortunately it was only set
to nullable. I could have sworn I set it to primary key and NOT
nullable (downside of using the IDE?). That will teach me to look at
all the obvious things with extreme care.
:)

In regards to your second question, just for FYI. I need merge
because I am using timestamps for optimistic concurrency and I want
all my guids to come from the server side.

Ah yes, right - you need it.
Thanks again for the help.

You're welcome.
 

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