Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieving the Value of an AutoGen Field
Message
From
29/12/2004 05:13:58
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
28/12/2004 23:54:12
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
VB.NET 1.1
Database:
MS SQL Server
Miscellaneous
Thread ID:
00972799
Message ID:
00972854
Views:
13
>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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform