xplorer00 xplorer00 - 3 months ago 36
Vb.net Question

Combobox combinatorics

I have a form with 3 combo boxes. The value of the combo boxes generates a SQL query with 3 parameters. The SQL generates a RDLC report.

For example:

Combox1 with values(v1,v2,v3,ALL)

Combox2 with values(v1,v2,ALL)

Combox3 with values(v1,v2,v3,4,ALL)

Me.ExampleTableAdapter.QueryWithParams(Me.ExampleDataSet.Table, Combobox1.SelectedIndex, Combobox2.SelectedIndex,Combobox1.SelectedIndex)


SELECT * FROM Table WHERE Column1=@c1 AND Column2=@c2 AND Column3=@c3

Ok, the problem is when the selected value is ALL in the combo X, I cannot get the values because I must change the query and kick out the parameter.
For example:
If the combo1, combo2, combo3 have the values ALL. I don't need parameters.


If the combo1 is ALL.

SELECT * FROM Table WHERE Column2=@c2 AND Column3=@c3

If combo1 and combo3 are ALL

SELECT* FROM Table WHERE Column2=@c2

Then in code I look which is the selected value of the combo and upon it I do the query.

Is there a way that i do this thing without generating all 8 types of queries?

PS. I cannot use stored procedures because I'm using SQL Server Compact


If the value for 'ALL' should be sent to the query with value 'NULL'

FROM Table 
WHERE (Column1=@c1 OR @c1 IS NULL)
AND (Column2=@c2 OR @c2 IS NULL)
AND (Column3=@c3 OR @c3 IS NULL)

Edit: Of course same can be done for any specified 'ALL'-value Example of 'ALL' = -1

(Column1=@c1 OR @c1 = -1)