Reputation: 1863
MY Table:
id address tag
1 test class1
2 test1 class2
3 test3 class3
in SP i wrote the select statement like this:
Select address from mytable where tag IN (@SingleParameter)
Passing parameters to SP from UI as:
string SingleParameter = "";
SingleParameter = "class1,class2,class3";
comand.Parameters.AddWithValue("@SingleParameter",SingleParameter);
Then not getting any results if records are there in table.
While sending single value like
string SingleParameter = "";
SingleParameter = "class1";
comand.Parameters.AddWithValue("@SingleParameter",SingleParameter);
then getting results. How to Pass multiple values in string to SP? Please tell me........
Upvotes: 2
Views: 792
Reputation: 6862
There are couple of ways to do this. Also, I believe there has already been a discussion here on so. I'd recommend checking out this and this links.
Basically, here are the options as I see them:
I'd recommend going with the second one, though it may not be portable to other databases (e.g. MySql doesn't have a notion of table-valued parameters). And definitely look at the articles - they are a great read.
Upvotes: 1