Home > SQL Development > How to get the primary key value from a just new created record ?

How to get the primary key value from a just new created record ?



<i><b>Originally posted by : Pascal (pascal.comminot@edu.ge.ch)</b></i><br />Hi<br /><br />I want to get the primary key value (autoincremented value) of a just new created record. But I got nothing with everything I tried.<br /><br />Lets take the following Table in my database<br /><br />id, primary key, autoincremented longint<br />somefield, text<br /><br />ConnectionStr = "DSN=somedatabase"<br />Set RS= Server.CreateObject("ADODB.RecordSet")<br /><br />RS.Open "MyTable", ConnectionStr, adLockOptimistic, adCmdTable<br /><br />RS.AddNew<br />RS("SomeField") = "Some value"<br />id1 = RS("ID")<br />RS.Update<br /><br />id2 = RS("ID")<br /><br />--> both id1 and id2 remain empty in my ASP code.<br />but If I look in the database, the record has been registered, and the if field contains a unique value.<br />

    
Guest


<i><b>Originally posted by : kalicharan (boorugu_kali@yahoo.com)</b></i><br /><br />Hello Friend,<br />I tried it once in my programming and got it.<br />I think u should get the value before assigning some value try it. In Access database I got this value.<br /><br />RS.AddNew<br />id1 = RS("ID")<br />RS("SomeField") = "Some value"<br />RS.Update<br /><br />Try out with this<br /><br /><br /><br /><br />------------<br />Pascal at 5/24/2002 6:55:32 AM<br /><br />Hi<br /><br />I want to get the primary key value (autoincremented value) of a just new created record. But I got nothing with everything I tried.<br /><br />Lets take the following Table in my database<br /><br />id, primary key, autoincremented longint<br />somefield, text<br /><br />ConnectionStr = "DSN=somedatabase"<br />Set RS= Server.CreateObject("ADODB.RecordSet")<br /><br />RS.Open "MyTable", ConnectionStr, adLockOptimistic, adCmdTable<br /><br />RS.AddNew<br />RS("SomeField") = "Some value"<br />id1 = RS("ID")<br />RS.Update<br /><br />id2 = RS("ID")<br /><br />--> both id1 and id2 remain empty in my ASP code.<br />but If I look in the database, the record has been registered, and the if field contains a unique value.<br />

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved