Can I use the following with ExecuteScalar?

R

RA

Hi

I have the following sql:

sql = "INSERT INTO Customers (FirstName, LastName) VALUES ('New', 'test');
SELECT id FROM Customers WHERE (id = SCOPE_IDENTITY())"

myCommand.CommandText (sql, cn);
Can I use it with ExecuteScalar and by that I will get the new id(Identity)
column value?

object id = cmdsql.ExecuteScalar ();



Thanks,
Ronen
 
M

Miha Markic

Ah, btw, you might replace "SELECT id FROM Customers WHERE (id =
SCOPE_IDENTITY())" with "SELECT SCOPE_IDENTITY"
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top