Lookup of a record once it is created

Results 1 to 2 of 2

Thread: Lookup of a record once it is created

  1. #1
    Mike Palmer Guest

    Default Lookup of a record once it is created

    Hello,<BR><BR>I need some help. I am using the following:<BR><BR>Set Conn = Server.CreateObject("ADODB.Connection")<BR>conn.op en "DATA"<BR>SQL = "INSERT INTO Table (Field) VALUES (Value)"<BR>Set RS = Conn.Execute(SQL)<BR><BR>How can I retreive a field value for within that statement.<BR><BR>Here is what I am trying to do. Create a new record and then retrieve the Primary Key value for the record before closing the connection. <BR><BR>Any suggestions,<BR><BR>Mike Palmer<BR>

  2. #2
    Jason Miller Guest

    Default RE: Lookup of a record once it is created

    Assuming that you&#039re using an AutoNumber for the primary key (which is why you don&#039t know it when you add the record), just take a "select primaryKey from table where (fields & values) order by primaryKey desc" and it&#039ll be the first record in that set.<BR><BR>Rumor has it that if you add "top 1" between "select" and "PrimaryKey", it&#039ll be even kinder to your server&#039s resources.<BR><BR>If you&#039re not getting an autonumber, I&#039d suggest adding a timestamp and referencing it the same way. Otherwise, as far as I know, you&#039re SOL.<BR><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