Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving the value of RETURN @@IDENTITY in C#

Tags:

c#

.net

ado.net

Here's a very simple question. I have an SP that inserts a row into a table and at the end there's the statement RETURN @@IDENTITY. What I can't seem to find is a way to retrieve this value in C#. I'm using the Enterprise library and using the method:

db.ExecuteNonQuery(cmd);

I've tried cmd.Parameters[0].Value to get the value but that returns 0 all the time. Any ideas?

like image 632
Malik Daud Ahmad Khokhar Avatar asked Dec 28 '25 14:12

Malik Daud Ahmad Khokhar


1 Answers

BTW, in most circumstances, you should use SCOPE_IDENTITY() rather than @@IDENTITY. Ref.

like image 69
Mitch Wheat Avatar answered Dec 30 '25 05:12

Mitch Wheat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!