Last post Oct 15, 2015 02:19 AM by Mikesdotnetting
Oct 14, 2015 09:26 AM|khadarmastan|LINK
I have been trying to send a string in sql parameter for "IN" clause in sql stored procedure from C#. But it did not work.Below is my c# code i have written
string s = "'Facebook','dropbox'"
using (SqlConnection objCon = new SqlConnection(connString))
using (SqlCommand objCmd = new SqlCommand("procedurename", objCon))
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.Parameters.Add("@paramname", SqlDbType.VarChar).Value = s;
using (SqlDataAdapter objDA = new SqlDataAdapter(objCmd))
can you please some one help me how to solve the problem.
Oct 14, 2015 10:11 PM|Weibo Zhang|LINK
Welcome to the ASP.NET Forums.
You could first debug your code step by step to make clear what and where error happens. The code above seems no error, you could refer to the following links to use check your code and use the “try-catch” to handle the exception. Then you could just execute
the stored procedure with the value “'Facebook','dropbox'” to check whether it could works.
Besides, the following links provide some solution that you could have a look. You could modify your “IN
clause” as a new “select clause” or create a function as the following second link shows to achieve your goal.
I hope it’s useful to you.
Oct 14, 2015 11:39 PM|jmpalines|LINK
you haven't executed your commnad
Oct 15, 2015 02:19 AM|Mikesdotnetting|LINK
I use the approach detailed in the Mitch Selers article referenced by Weibo Zhang, but you can also use XML: http://raresql.com/2011/12/21/how-to-use-multiple-values-for-in-clause-using-same-parameter-sql-server/