Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
FillSchema and Identity column
Message
From
10/01/2003 10:28:15
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00740181
Message ID:
00740286
Views:
20
Don,

We determine a table's PK not by the schema but through naming conventions that we set up when we designed the Database ... unfortunately, you may not have the luxury of designing your Database yourself. But, what we did is to name the PK the same as the table. So, if we have a Personnel table, then the PK for it is PersonnelKey. Every table in our database works like this, so we do not have to set up our DataSets with a specified PK column since we already know what it is.

This may not work for you if you can't mess with your database's schema, but I thought I'd mention it as a suggestion in case you can.

~~Bonnie


>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
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform