I've got a form which I'm syncing with a dataset. My problem is that when I create a new record, which'll get added to the database using the insertcommand that the SqlCommandBuilder built, the dataset doesn't contain the new record's primary key value. So if I then call Update on the adapter again for this record (which'll then use the updatecommand as the record already exists), I get the following error:
"Concurrency violation: the UpdateCommand affected 0 of the expected 1 records."
This is because the update command's WHERE clause parameter that should contain the primary key value, instead contains NULL.
It works if in my form, I add the new record, then close and reopen the form, then change the fields, then update. This is because it's rebinding when the form loads. I just can't insert, then update a record without rebinding the controls.
I'm probably misunderstanding something fundamental here. Should there be something else I'm calling to set the primary key field in the dataset after a new record gets inserted?
Thankyou for any help with this, Dan.
|