Get ID (Identity field) from a new record

  • Thread starter Thread starter fantavir
  • Start date Start date
F

fantavir

Hi,
I'm trying to insert a new record in a Table (the field ID is numeric,
counter and primary key) and get the value of the field ID, using
ADO.NET.

Accessing recordset (rst below) by ADO I can do:
rst.addnew
rst("Name")="Joe"
rst("Surname")="Smith"
rst.update
myID = rst("ID")

Then I use 'myID' to insert a new record in another table.

How can I do the same thing using ADO.NET (example, with DataReader,
DataTable, DataSet)?

Thanks,
Francesco
 
On 20 Dec 2005 01:24:21 -0800, (e-mail address removed) wrote:

¤ Hi,
¤ I'm trying to insert a new record in a Table (the field ID is numeric,
¤ counter and primary key) and get the value of the field ID, using
¤ ADO.NET.
¤
¤ Accessing recordset (rst below) by ADO I can do:
¤ rst.addnew
¤ rst("Name")="Joe"
¤ rst("Surname")="Smith"
¤ rst.update
¤ myID = rst("ID")
¤
¤ Then I use 'myID' to insert a new record in another table.
¤
¤ How can I do the same thing using ADO.NET (example, with DataReader,
¤ DataTable, DataSet)?

The following should help:

http://msdn.microsoft.com/library/d...cpconRetrievingIdentityOrAutonumberValues.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadonet/html/manidcrisis.asp


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top