General information
Title:
FillSchema and Identity column
I'm writing a generic WinForms routine to insert a record, then return the @@identity value and store it back to the current row, so I can then add child records with the correct parent PK.
I have an OnRowUpdated procedure that figures out the Primary Key for the current datatable using the "DataTable.PrimaryKey" property.
To do this I had to retrieve the datatable schema using this command:
DataAdapter.MissingSchemaAction() = MissingSchemaAction.AddWithKey
Now I indeed can figure out Primary Key field for the current table. But now I am getting a "Field is read-only" when I try to store the returned @@IDENTITY value back into the table. Before using the MissingSchemaAction I could store a value but couldn't determine the PK field! Kind of a catch-22 so far!
Does anyone know the way to return and store an @@identity value for a table using a generic routine that figures out the PK field programmatically? I'm trying to avoid hard-coding the insert for every table.
Note: It's interesting that with "MissingSchemaAction.AddWithKey" in effect I DO get a local auto-incrementing field value now, but it's NOT in synch with the server's current value, so the functionality appears useless. In other words, if other user's add records to the server while I'm working locally my local "autoincrement" fields are duplicate IDs, so I can't use the values to create child records. So I do the "SELECT @@IDENTITY" in my OnRowUpdated to retrieve the server's value.
Any advice is appreciated!
TIA
Don Meuse
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only