Skip to content
Advertisement

How to add in a sql query a condition that checks if ckeckboxe are checked?

I have several comboboxes and I would like to check those that are checked to retrieve their values ​​and use them in a sql query.

I tried to put all the checkboxes in a flowLayoutPanel and use a foreach to retrieve their contents.I think it’s a syntax problem in my sql query.

Here is the mistake I get : An unhandled exception of type ‘System.Data.SqlClient.SqlException’ occurred in System.Data.dll

Additional information: Invalid column name ‘selection’.

Sorry if the solution is obvious I am a beginner. Thanks for your help.

Advertisement

Answer

Your actual error is caused by the word selection. This is not the list variable but a literal text inside a string and the database engine has no way to know how to extract the list values from that word. So it thinks that you have written a column name and it cannot find it.

The solution is more complex than you think.

You need a collection of parameters and a collection of names to put inside an IN clause

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement