Parameterized Querys

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
Posts: 4
Joined: Mon 17 Oct 2005 19:52

Parameterized Querys

Post by enzers » Mon 05 Dec 2005 19:26

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.


Post by Serious » Tue 06 Dec 2005 14:50

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.

Code: Select all

SELECT * FROM Materials WHERE (Type=:Type) AND (:IgnoreMaterial=1 or Material=:Material)
If you want to ignore 'Material' parameter just set 'IgnoreMaterial' = 1, if you don't, set 'IgnoreMaterial' = 0.

Post Reply