Retrieving primary key value

  • Thread starter Thread starter ADO.NEWBIE
  • Start date Start date
A

ADO.NEWBIE

I add a record to an Access db table using the following
code...


ds.Tables(0).Rows.Add(dr)
da.Update(ds, "Clients")

At this point I want to retrieve the unique ID contained
in the Access table for the new record. How do I do that?
 
Not sure about Access, but using an output parameter is
the way to do it in SqlServer. see if you can add a
parameter with oledb command and see if the parameter
direction 'output' is available.

If not, I think you're going to have to rehit the db and
find the last record using executescalar method of the
command object.

Hopefully, this helps a little.

Good Luck,

Bill

W.G. Ryan
(e-mail address removed)
www.knowdotnet.com
 
ADO.NEWBIE said:
I add a record to an Access db table using the following
code...


ds.Tables(0).Rows.Add(dr)
da.Update(ds, "Clients")

At this point I want to retrieve the unique ID contained
in the Access table for the new record. How do I do that?

Use the "SELECT @@IDENTITY" statement.
It's best to combine it with an OnRowUpdated event handler
for your DataAdapter. Look here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconretrievingidentityorautonumbervalues.asp
(remove any linebreaks)
 
Back
Top