Puzzled & "SELECT Scope_Identity()"

  • Thread starter Thread starter Lloyd Dupont
  • Start date Start date
L

Lloyd Dupont

I used a SqlAdapter.

I have an InsertCommand whose CommandText goes like that

INSERT INTO table ( field1, field2, ...) VALUES ( @field1, @field2, ... )

I have an event handler for the RowUpdated event
which goes like that:

IDbCommand cmd = myConn.CreateCommand();
row[identity] = cmd.ExecutScalar();

and recently it began to bug and ExecuteScalar() to return alway
DBNull.Value
but there IS an idenity column in my table !

What could be going on ?
Any clues ?
 
Hi Lloyd,

Why don't you use the following:
INSERT INTO table ( field1, field2, ...) VALUES ( @field1, @field2,
.... );SELECT Scope_Identity()
The adapter will take care of identity automatically in this case.
 
solved.
I have SqlServer 8
but my DataBase is probably from am earlier version and didn't contain the
Scope_Identity() stroed procedure.
if it returns null I try
SELECT @@IDENTITY
 
Back
Top