I wish to retrieve the identity of a record I've just previously written (using ADO to MS SQL 2000 DB).
Like this....
(table TEST_TABLE has an identity column)
sSQL = "INSERT INTO TEST_TABLE (TESTFIELD1 ) "
sSQL = sSQL & "VALUES(?)"
Set oCommand = New ADODB.Command
Set oCommand.ActiveConnection = ADOConn
oCommand.CommandText = sSQL
oCommand.CommandType = adCmdText
oCommand.Parameters(0) = "ABC"
oCommand.Execute
Dim vID as Variant
sSQL = "Select SCOPE_IDENTITY()"
oCommand.CommandText = sSQL
vID = oCommand.Execute
vID contains Null yet all the blurb I've read says it should contain the unique ID of the new record.
If I replace SCOPE_IDENTITY() with @@IDENTITY it works...however the scope of this is global so presumably will not be correct 100% of the time.
Any help would be appreciated...thanks
Like this....
(table TEST_TABLE has an identity column)
sSQL = "INSERT INTO TEST_TABLE (TESTFIELD1 ) "
sSQL = sSQL & "VALUES(?)"
Set oCommand = New ADODB.Command
Set oCommand.ActiveConnection = ADOConn
oCommand.CommandText = sSQL
oCommand.CommandType = adCmdText
oCommand.Parameters(0) = "ABC"
oCommand.Execute
Dim vID as Variant
sSQL = "Select SCOPE_IDENTITY()"
oCommand.CommandText = sSQL
vID = oCommand.Execute
vID contains Null yet all the blurb I've read says it should contain the unique ID of the new record.
If I replace SCOPE_IDENTITY() with @@IDENTITY it works...however the scope of this is global so presumably will not be correct 100% of the time.
Any help would be appreciated...thanks