I have set up a query using the MySQLDataAdapter Editor. The query contains four parameters, though for simplicity I show only two parameters in the following example:
SELECT * FROM Materials WHERE (Type=@Type) AND (Material=@Material)
When using the query, there are times when I want to specify only one parameter. Is there any way to set the unused parameter to the equivalent of a wildcard character so it accepts all values? If I leave the parameter blank or set it to Nothing I get zero results from the query.
Parameterized Querys
There are two solutions of your problem.
First, you can use 'LIKE' clause. For additional information refer to MySQL documentation.
Second, you can use additional parameter to indicate that main parameter is not used.If you want to ignore 'Material' parameter just set 'IgnoreMaterial' = 1, if you don't, set 'IgnoreMaterial' = 0.
First, you can use 'LIKE' clause. For additional information refer to MySQL documentation.
Second, you can use additional parameter to indicate that main parameter is not used.
Code: Select all
SELECT * FROM Materials WHERE (Type=:Type) AND (:IgnoreMaterial=1 or Material=:Material)