I am wondering if anyone can point me in the right direction so I can save the returned identity value from one of my stored procedures. How can I save it into a variable. Any help or examples is appreciated thanks!
functionalCode
0
Light Poster
Recommended Answers
Jump to PostIf your stored procedure returns value just one value (which returns form aggregate functions) use SqlCommand and give it stored procedure name and then execute it as Scalar; it returns object you then can cast it
Object GetValue (string procName) { //I didn't assume stored procedure takes …
Jump to PostPlease mark it as solved if it's.
SELECT MAX(PK) FROM yourTable
Using Max(PK) is a dangerous practice to get an identity value :(
Use:
Select Cast(SCOPE_IDENTITY() as int) --or Select @@IDENTITY
They are slightly different and you should use
SCOPE_IDENTITY()
for your purpose.
All 7 Replies
Ramy Mahrous
401
Postaholic
Featured Poster
functionalCode
0
Light Poster
Ramy Mahrous
401
Postaholic
Featured Poster
functionalCode
0
Light Poster
Ramy Mahrous
401
Postaholic
Featured Poster
sknake
1,622
Senior Poster
Featured Poster
Ramy Mahrous
commented:
Yes, I agree
+8
Ramy Mahrous
401
Postaholic
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.