Get ID (Identity field) from a new record

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
 
P

Paul Clement

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top