If the search page submits more than one search parameter to the server, then you must write a SQL query and use the search parameters in SQL variables.
NOTE |
|
If you have only one search condition, you can use the simple DataSet dialog box to define your DataSet (see Searching with only one search parameter (ASP.NET)). |
If the simple dialog box appears instead, switch to the advanced dialog box by clicking the Advanced button.
The connection should be to a database containing data you want the user to search.
Make sure the statement includes a WHERE clause with question mark (?) placeholders for the search parameters. The following example contains two placeholders:
SELECT EMPLOYEEID, FIRSTNAME, LASTNAME, DEPARTMENT, EXTENSION FROM EMPLOYEE WHERE LASTNAME LIKE ? AND DEPARTMENT LIKE ?
For help on SQL syntax, see SQL Primer.
The parameters must be listed in the same order they appear in the SQL statement.
In the Name text box, enter any valid parameter name. The name cannot contain any spaces or special characters.
In the Type pop-up menu, select a data type. For example, if the parameter will hold text, select WChar.
In the Value box, enter the server variable that will contain the parameter value. For example, if the name of the form control on the search page is txtCity, then a server variable called Request.Form("txtCity") will be created and a value stored in it.
You can also enter a more complete expression that specifies a default value in case the server variable doesnt exist. For example, if searching a Microsoft Access database, you can use % as a default value. The following expression checks to see if the server variable Request.Form(
"txtCity
")
exists. If the variable exists (that is, if its not equal to nothing), the expression returns the variables value; if it doesnt exist, the expression returns the default value of %
.
(IIf((Request.Form("txtCity") <> Nothing), Request.Form("txtCity"), "")) + "%"
For more information, see a Visual Basic or C# language reference.
The default values simulate the values that would otherwise have been returned from the search page. Click OK to close the test DataSet.
Dreamweaver inserts the SQL query in your page.
The next step is to display the search results in a DataGrid. See Displaying the results in a DataGrid.