>Happy Holidays to one and all!!!
>
>I have a table with several fields, one of which is an AutoGen field, wherein a value is automatically assigned by SQL every time I add a record. My goal is to determine the value of this field for the record(s) which I add using DataAdapter.Update(DataTable).
>
>After calling the update I checked the field value in the DataTable but all I get is a NULL value. Does this mean I need to call the DataAdapter.Fill(DataTable) method every time I add a record just to check the value of this field? Or is there a better way of doing this?
>
>Many thanx! in advance 8 )
>
>Martin
Martin,
Depends on what you want to do with that value.
If you'd use that just to track records in your disconnected set then you don't need backend assigned value (do not show them to users). Using AutoIncrementSeed, AutoIncrementStep values of -1 for your dataset you'd distinguish new rows checking only the id column.
If you need them somehow then there are few methods and depend on backend.
-Batch queries (ie: InsertCommand is something like - "insert into ... values ... ; select scope_identity() as myId" )
-Stored procedures (stored procedure returns identity inserted)
-Handle RowUpdated event (ExecuteScalar with query retrieving last identity)
What I do is simplier and more reliable IMHO. I don't use AutoIncrement values:) Instead I use GloballyUniqueIDentifier - GUID values. I can generate them on disconnected set and submit to backend. When retrieved they're still the same values I generated initially. In backend I've it as a default value but almost all the time I generate and submit (a bulk insert for example uses default).
(I personally disagree with objections to it related to performance).
Cetin