Click here to Skip to main content
15,879,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi

In my DO table SlNo column have identity now i i have to set Scope identity for the same.below my code
C#
string sqlcommand = "SELECT DoNo,SlNo from DO where DoNo = DoNo, SET @SlNo=CAST(SCOPE_IDENTITY() AS int";

Could you please help how to set?

At present i am getting a error msg error near int.

Regards
Lancy
Posted
Updated 5-Nov-11 5:39am
v2

Try reading this http://msdn.microsoft.com/en-us/library/ms190315.aspx[^] to understand what SCOPE_IDENTITY is.
 
Share this answer
 
Try this :

C#
string sqlcommand = "SELECT DoNo,SlNo from DO where DoNo = DoNo; SET @SlNo=CAST(SCOPE_IDENTITY() AS int)";


Substituted "," by ";" between two commands and added a parentheses at the end.
 
Share this answer
 
Comments
[no name] 6-Nov-11 10:32am    
You should also read what SCOPE_IDENTITY is. It has no bearing on select statements and is meaningless in this context
Amir Mahfoozi 6-Nov-11 14:44pm    
However you're right and also I know its function but I was focusing on : "At present i am getting a error msg error near int.". And I agree with you that SCOPE_IDENTITY is non applicable in here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900