SQL @@IDentity

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I posted a post earlier but for some reasons it didn't show up.

AW, I want to grab the rowid(Primary key) of last row inserted. I tried but
it gives me error regarding cast.The column is int and I tried
datareadter.getint32(0) but it didn't work.

Also can I execute two queries within one execution? for example
Command.Text = "insert a row into atable select @@IDENTITY from atable"

Any help??
 
If you put a semi-colon after the insert statement, you can put a select on
after it.
 
Yes, this works--assuming your DBMS supports it--not all do (even without
the semicolon).
On the other hand, if this is SQL Server, we don't recommend using
@@Identity as it returns the last ID generated--but it could have been
generated by a trigger and not on the inserted table. We recommend using
SCOPE_IDENTITY() instead...

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top