Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
FillSchema and Identity column
Message
 
To
All
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
FillSchema and Identity column
Miscellaneous
Thread ID:
00740181
Message ID:
00740181
Views:
95
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
Map
View

Click here to load this message in the networking platform