Creating a Parameter Query

To create a row-returning, parameterized query, simply add the parameters to the query's SQL string. The parameters must be defined by using the Parameters keyword, as in the following:

strSQL = "Parameters [Type Country Name] Text;" & _ "SELECT Customers.* FROM Customers WHERE " _ & "Customers.Country=[Type Country Name];"

The above SQL statement begins by defining one parameter called Type Country Name. This parameter will be able to accept text entries. The second part of the SQL statement selects all the records from the Customers table that have an entry in the Country field equal to the provided parameter value.

The complete procedure is shown in Hands-On 15-4. Because the ADO Command object always creates a temporary query, you must append the Command object to the ADOX Procedures collection in order to save a parameterized query in a database.

0 0

Post a comment