I’m trying to retrieve the @@IDENTITY value from an access database after I add a row to it. However, instead of using hard coded connections, I’m using the DataSet wizard. Unfortunately, due to the Jet engine, I can’t do more than one command at a time. I tried to select the @@IDENTITY in a separate command but unfortunately, I guess it counts as a different command as it returns a 0 each time.
My question is, is there a way I can use the GUI/IDE to retrieve the @@IDENTITY or do I have hard code the connection, command, query values and obtain the value that way.
Thanks.
You asked an interesting questions which I did not know the answer to. After some research I found this and it seems promising. However I have never used it and cannot substantiate if and how well it works.
I also don’t know the
DataSet wizardthat well, but vaguely recalls that it generates anOleDbAdapterobject, hopefully it exposes aRowUpdatedevent which you can hook this code to.I have pasted the interesting MSDN code parts here:
(Link to full documentation)
Then hook-up and event listener to
RowUpdatedObtain the
@@Identitywith the same connection.Hopefully this helps you out or least someone will set me straight 🙂