SELECT @@Identity How to

Results 1 to 2 of 2

Thread: SELECT @@Identity How to

  1. #1
    Join Date
    Dec 1969

    Default SELECT @@Identity How to

    I have a question and was hoping someone can help<BR><BR>In Clasic asp i could do something like this<BR><BR><BR>set rcs = db.execute("INSERT.....; SELECT @@IDENTITY").nextrecordset<BR>newidentity = rcs(0)<BR>rcs.close<BR>db.close<BR><BR>to get the identity of a newly inserted record<BR><BR>anyone know how to do this with and a SqlConnection

  2. #2
    Join Date
    Dec 1969

    Default a sample & a link

    Hey Tony, <BR><BR>First off, you should probably hit:<BR><BR><BR><BR>For an overview of dealing with data access and SQL if you haven&#039;t already. <BR><BR>As for the specifc question, run the following after your insert: <BR><BR>dim someCommand AS new SqlCommand("SELECT IDENT_CURRENT(&#039;someTable&#039;)", someConnection)<BR><BR>dim newIdentity AS integer = someCommand.ExecuteScalar<BR><BR>That only works if you&#039;re using SQL2k, if using SQL7 use @@IDENTIY just as you have been. <BR><BR>I&#039;m not sure if it&#039;s possible to do both the insert and the ident query at once. If so, you&#039;d probably still use executeScalar to grab the single value. <BR><BR>hth,<BR>])ry<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