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

2 Answers 2

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."

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.