[thelist] Key ID of Record Just Created?

Casey aspnet at thecrookstons.com
Tue Aug 23 19:06:19 CDT 2005


> @@IDENTITY is good, but SCOPE_IDENTITY() is better:


a.. @@IDENTITY returns the last identity value generated for any table in
the current session, across all scopes.

a.. SCOPE_IDENTITY returns the last identity value generated for any table
in the current session and the current scope

Okay.  I can see why SCOPE_IDENTITY would be better.  But, I'm still not
sure how to implement either one :-(

As mentioned in my last post, I have been able to figure this much out
(below).  Did I use SCOPE_IDENTITY properly, and, how would I then determine
the value of Identity?!?!?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Dim conAddDoc As SqlConnection = New
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("MccCon
String"))

Dim strInsert As String = "Insert MCCIME_Doctor (fname, lname, specialty,
...) VALUES (@fname, @lname, @specality, ...) SELECT @@IDENTITY AS
'Identity'"

~~!! OR ?? !!~~

Dim strInsert As String = "Insert MCCIME_Doctor (fname, lname, specialty,
...) VALUES (@fname, @lname, @specality, ...) SELECT SCOPE_IDENTITY AS
'Identity'"

Dim cmdInsert As SqlCommand = NEW SqlCommand(strInsert, conAddDoc)

conAddDoc.Open
  cmdInsert.ExecuteNonQuery()
conAddDoc.Close



More information about the thelist mailing list