I have a delimiter string like this: “2,3” which is grabbed from a listbox values which I will pass to my SProc parameter:
AddInParameter(dbCommand, "@Mode", DbType.String, 50, DBNull.Value)
If Not String.IsNullOrEmpty(.MemshpT) Then
dbCommand.Parameters("@Mode").Value = .MemshpT 'MemshipT will contain "2,3"
In my SProc I have a condition like this:
and Cast(T.Mode as varchar(20)) in(@Mode))
Now in my listbox which contains values: 1,2,3,4. If I select the values individually say ‘1’ and pass it to my SQL parameter, I will have all activity type 1 results in my gridview, but if I highlight more then 1 values it returns nothing because the string becomes like “2,3” which (Mode is not null and T.Mode like ‘%’ + @Mode + ‘%’) doesn’t seem to be able to catch. How can I reconstruct my delimiter or SQL query such that single as well as multiple delimited values (e.g. “1,2” will return all activity of 1 and 2) will be detected and be displayed in my gridview. Thanks.
I’m assuming that MODE is integer data type and can only have 1 value per record.
so your search string looks like 1,2,3,4
the values in your database field mode look like
1
2
3
4
I think you want to use the IN operator not like..
which would result in 1 in (1,2,3,4)