Retrieving ID number

Results 1 to 5 of 5

Thread: Retrieving ID number

  1. #1
    Neils Guest

    Default Retrieving ID number

    I have an ID number field in an SQL DB that is generated when I add a new record using INSERT. Is there a way (using the ADODB objects in ASP) to grab this ID number at the same time that I perform the INSERT?

  2. #2
    MG Guest

    Default RE: Retrieving ID number

    I don&#039t believe so, since the update command does not return a recordset.

  3. #3
    iyyappan n iyer Guest

    Default RE: Retrieving ID number

    generated id numbers start from 1, are incremented.<BR>so , after adding a record, create a rs , with the following <BR>order by id, and move to the last record, and read id value, and u will get the id value that got generated for the most recent record. i have tried it.<BR>

  4. #4
    Join Date
    Dec 1969

    Default RE: Retrieving ID number

    (1). You can&#039t be sure ID retrieved via rs as you suggested is yours. think about it: 2nd person might insert a record right before your rs is established and your rs will now get this 2nd person&#039s ID not yours.<BR>(2). Waste of resource, hitting Db un-necessary (I still do always the time).<BR> <BR>There are several ways to accomplish your task while avoiding problem (1) and (2):<BR>A. If you use adodb.recordset, you can do something like this:<BR>&#060;%<BR>dim myId<BR>dim rs<BR>--<BR>&#039&#039set rs = sever.createobject("adodb.recordset") etc.<BR>rs.addnew<BR>rs("this") = this<BR>rs("that") = that<BR>rs.Update<BR>myId = rs("ID") &#039&#039&#060; this is what you want<BR>rs.close<BR>set rs =nothing<BR>---<BR>%&#062;<BR>B. Write a stored proc make use of @@identity<BR><BR><BR>

  5. #5
    shiva l shapur Guest

    Default RE: Retrieving ID number

    Hey do one thing develop a component in vb for database insertion and in that component you retreive latest from database ie max as u will be using component u wont get any problem or else go for stored procedure.<BR>if u wanna code for vb component i will get u <BR>contact me at<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts