Datasets and autonumber

hog

Well-known member
Joined
Mar 17, 2003
Messages
984
Location
UK
If I have an object that has been updated with user data and then the objects .Add method is called to create the record in the Access database then is there any easy way of getting the AutoNumber generated by Access other than finding a way to read back in the new record?
 
No hog, you can do that if only user is using your application at a time and thus you would fetch the maximum id from the Access database upon filling the dataset. But ofcourse if more than one user is using your application then this number would be meaningless since new rows are added all the time
 
I heard differently awhile back. If you issue two separate calls to Access, one to do the INSERT and one to do the "SELECT @@IDENTITY" to get the last inserted AutoNumber value, it should work. This assumes each user has their own always-on connection to the DataBase (usually how you program against Access).

Its a bit easier in SQL Server since you can do the INSERT and SELECT @@IDENTITY in one calls, but it doesnt work in Access for dynamic SQL. If youre calling a stored proc in Access (which you must create using dynamic sql using something like "CREATE PROC...", you *might* be able to have the proc do an INSERT and SELECT, but I havent tried it (nor have I tried creating procs in Access, though I hear-tell you can).

-Nerseus
 
Thx Nerseus:)

I have decided to take a different approach to solve this issue. However you points will be noted as this is the second time Ive required this, so you never know:) :)
 
Back
Top