Click here to Skip to main content
15,911,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using Stored Procedure for my project. IN keyword used within procedure, values are passing through parameter. I am not getting output. Only raise error.

SQL Codes:
SQL
Create Proc TestPro @Parameter Varchar(100)
as
Declare @QueryStr Varchar(1000)
set @QueryStr='Select Col1,Col2,Col3,Col4 from Table where Col1 in('+ @Parameter+ ')'
Exec (@QueryStr)


C# Code:
C#
string strPrValue="'ABC/01','ABC/02','ABC/03'";
SqlConnection sconPM = new SqlConnection(Constring);
SqlCommand sCmd = new SqlCommand("TestPro", sconPM);
SqlDataAdapter DA = new SqlDataAdapter(sCmd);
DataSet ds = new DataSet();
sCmd.Parameters.Add("@Parameter", SqlDbType.VarChar).Value = strPrValue;
sCmd.CommandType = CommandType.StoredProcedure;
DA.Fill(ds);


if i pass only one value(ABC/01) in parameter its working fine , if many value in parameter raise error like "incorrect syntax near ABC/"
Posted
Updated 24-Jul-10 7:01am
v6
Comments
Sandeep Mewara 24-Jul-10 11:54am    
Care to add what error?

Further, what kind SP is that? Do check in SQL if the expecte query formed do actually execute!
Rajesh Sajjanar 24-Jul-10 13:38pm    
Hi In C# ABC/" causing the problem, try executing the query in the SQL query analyser and see if it works , the problem is with ABC/" otherwise your query is correct

What error are you getting?

Try removing the '' from ('+ @Parameter+')';
and see if this works.
 
Share this answer
 
Comments
Murugesan Solaiyappan 24-Jul-10 13:00pm    
my code is not working for IN keyword only,otherwise no problem
For single value you pass it runs fine but for multiple it not work..
Try this one like string strPrValue="'''ABC/01''','''ABC/02''','''ABC/03'''";
 
Share this answer
 

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