c# - Using IN operator with Stored Procedure Parameter -


i building website in asp.net 2.0, description of page working about: listview displaying table (of posts) access db, , listbox multiple select mode used filter rows (by forum name, value=forumid). converting listbox selected values list, running following query.

parameter:

oledbparameter("@q",list.tostring()); 

procedure:

select * sp_feedbacks forumid in ([@q]) 

the problem is, well, doesn't work. when run msaccess 2007 string 1,4, "1","4" or "1,4" 0 results. query works when 1 forum selected. (in (1) instance).

  • solution? guess use many or's avoid option. solution convert datatable list filter using linq, seems messy option.

thanks in advance, bbln.

when have:

col in ('1,4') 

this tests col equal string '1,4'. not testing values individually.

one way solve using like:

where ','&@q&',' '*,'&col&',*' 

the idea add delimiters each string. so, value of "1" becomes ",1,"in column. value of "1,4" @q becomes ",1,4,". when comparison, there no danger "1" match "10".

note (for not know). wildcard like * rather sql standard %. however, might differ depending on how connecting, use appropriate wildcard.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -