Pass value to a stored procedure in ms sql [duplicate]

问题内容:

This question already has an answer here:

This is how I get the value of the selected column in a gridview in my code behind(C#)

str += "'" + MyGridview.DataKeys[gvrow.RowIndex].Value.ToString() + "',";

This is the value of str

str='7','101','235','456'

My output here is correct. My problem is i got error when i pass this value on stored procedure parameter.

This is the way I pass this value to my stored procedure;

: some other parameter here
cmD.Parameters.AddWithValue("@Rec",str);

And on my stored procedure this is how i get this

Declare @Rec AS NVARCHAR(MAX)

Select col1,col2 where Record_no in ('' + @Rec + '') 

My error is

Conversion failed when converting the nvarchar value 

问题评论:

1  
What is the exact value of str you are passing to the stored proc?
1  
show me your stored proc.

原文地址:

https://stackoverflow.com/questions/47747671/pass-value-to-a-stored-procedure-in-ms-sql

添加评论