0

I have a CheckBoxList that is showing all A table C column.

SELECT  DISTINCT C
FROM A
ORDER BY C

My A table has two columns.

B-->Primary Key

C--> Every C has a unique B.

I have an SQL like this for my Gridview Source;

Select <...............>
From <..................>
Where <.................>
AND A.B IN 
(Select A.B 
From A 
Where A.C IN ALL CheckBoxList.SelectedItem.Value)

Something like that. My SQL syntax isn't very good. I hope you can tell what I want..

What I REALLY want is, when I click a button, Gridview should be populated according to the SQL , BUT filtered by what is selected in CheckBoxList.

Is there any way to add a parameter in the SQL IN clause? How can I do that?

Best Regards,

Soner

AndyG
  • 39,700
  • 8
  • 109
  • 143
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364

2 Answers2

1

Different Solution is discussed in the following URL : Parameterize an SQL IN clause Have a look at it.

Community
  • 1
  • 1
varadarajan
  • 514
  • 1
  • 3
  • 9
1

When I encountered an issue like this, I took a data table (precomputed, equivalent to all the boxes being checked) and just used a LINQ query (I asked about that query here). Basically, in the context of your question, I just used a standard LINQ query, building a filter by ORing all the checkboxes to form a filter. I created the filter itself using PredicateBuilder. I only needed the 26 lines of code under "Predicate Builder Source Code."

Community
  • 1
  • 1
Brian
  • 25,523
  • 18
  • 82
  • 173