Finding the Primary Key of a Just added record.

H

Hugh O

Hi,
I have a Web app using VS.Net 2003, ASP and VB. I am using RDO with a SQL
Server 2000 database. The code below shows an example of a NewRow method.
In the first column there is a integer field that is set as the primary key
and with Identity (1,1)
rRow1 = iDataSetA.Tables("tCurSessions").NewRow()

rRow1("sesSessionCnt") = 0

rRow1("sesSessionStart") = Now()

rRow1("sesSessionStop") = Now()

rRow1("sesSessionSecs") = 0

rRow1("sesUserUnq") = 0

rRow1("sesUserTyp") = 0

rRow1("sesUserIDX") = 0

rRow1("sesUserZipUnq") = 0

iDataSetA.Tables("tCurSessions").Rows.Add(rRow1)

iAdapCurSess.Update(iDataSetA, "tCurSessions")

After this Adaptor Update to the server is there a way that I can easily get
the value of that primary key of that record that I just added.

thanks,

hugh
 
H

Hugh O

Peter,
Thank you.

I was hoping that there might be another option than simply passing the
data. But you have confirmed what I thought. My app may need to
re-retrieve that new record soon after it is written. That could be
inefficient when I do not know the key. I guess I can do it with another
index but was hoping to avoid that.

Thanks for the response.
hugh
 
P

Peter Huang [MSFT]

Hi Hugh,

I think the Identity's autoincrease is done in the Server side, the client
ADO.NET will not know the result until we retrieve it again from Server.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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