ado| Tutorials | data
Site original content, reproduced please indicate the source Web page teaching network .
We can use SQL statements to create a query that shows the data in the database we need by condition.
For example, the name of the company that displays "Companyname" starting with a. The following code can be implemented:
<body>
<%
Set Conn=server.createobject ("ADODB. Connection ")
Conn. Provider= the "microsoft.jet.oledb.4.0"
Conn. Open "E:/webjx/webjx.mdb"
Set Rs=server.createobject ("Adodb.recordset")
Sql= Select Companyname, ContactName from Customers WHERE CompanyName like ' a% '
Rs. Open SQL, conn
%>
<table border= "1" width= "100%"
<tr>
<%for each x in Rs. Fields
Response.Write ("<th>" & X.name & "</th>")
Next%>
</tr>
<%do until Rs. Eof%>
<tr>
<%for each x in Rs. Fields%>
<td><%response.write (x.value)%></td>
<%next
Rs. Movenext%>
</tr>
<%loop
Rs.close
Conn.close%>
</table>
</body>
Displays information for companies with the start letter greater than E in "Companyname":
<body>
<%
Set Conn=server.createobject ("ADODB. Connection ")
Conn. Provider= "Microsoft.Jet.OLEDB.4.0"
Conn. Open (Server.MapPath ("E:/webjx/webjx.mdb"))
Set rs = Server.CreateObject ("Adodb.recordset")
Sql= "Select Companyname, ContactName from Customers WHERE companyname> ' E '"
Rs. Open SQL, Conn
%>
<table border= "1" width= "100%" >
<tr>
<%for each x in Rs. Fields
Response.Write ("<th>" & X.name & "</th>")
Next%>
</tr>
<%do until Rs. Eof%>
<tr>
<%for each x in Rs. Fields%>
<td><%response.write (x.value)%> </td>
<%next
Rs. Movenext%>
</tr>
<%loop
Rs.close
Conn.close
%>
</table>
</body>
Information about the company that displays "Country" as:
<body>
<%
Set Conn=server.createobject ("ADODB. Connection ")
Conn. Provider= "Microsoft.Jet.OLEDB.4.0"
Conn. Open (Server.MapPath ("E:/webjx/webjx.mdb"))
Set rs = Server.CreateObject ("Adodb.recordset")
Sql= "Select Companyname, ContactName from Customers WHERE country= '"
Rs. Open SQL, Conn
%>
<table border= "1" width= "100%" >
<tr>
<%for each x in Rs. Fields
Response.Write ("<th>" & X.name & "</th>")
Next%>
</tr>
<%do until Rs. Eof%>
<tr>
<%for each x in Rs. Fields%>
<td><%response.write (x.value)%> </td>
<%next
Rs. Movenext%>
</tr>
<%loop
Rs.close
Conn.close
%>
</table>
</body>
The user chooses the country and then displays the appropriate information:
<body>
<%
Set Conn=server.createobject ("ADODB. Connection ")
Conn. Provider= "Microsoft.Jet.OLEDB.4.0"
Conn. Open (Server.MapPath ("E:/webjx/webjx.mdb"))
Set Rs=server.createobject ("Adodb.recordset")
Sql= "Select DISTINCT Country from Customers order by Country"
Rs. Open Sql,conn
Country=request.form ("Country")
%>
<form method= "POST" >
Select Country: <select name= "Country" >
<% do Until Rs. Eof
Response.Write ("<option")
If Rs.fields ("Country") =country Then
Response.Write ("selected")
End If
Response.Write (">")
Response.Write (Rs.fields ("Country"))
Rs. MoveNext
Loop
Rs. Close
Set Rs=nothing%>
</select>
<input type= "Submit" value= "Show info" >
</form>
<%
If country<> "" Then
Sql= "Select Companyname,contactname,country from Customers WHERE country= '" & Country & "'"
Set Rs=server.createobject ("ADODB. Recordset ")
Rs. Open Sql,conn
%>
<table width= "100%" cellspacing= "0" cellpadding= "2" border= "1" >
<tr>
<th> Company Name </th>
<th> Contact Person </th>
<th> National </th>
</tr>
<%
Do Until Rs. Eof
Response.Write ("<tr>")
Response.Write ("<td>" & Rs.fields ("CompanyName") & "</td>")
Response.Write ("<td>" & Rs.fields ("ContactName") & "</td>")
Response.Write ("<td>" & Rs.fields ("Country") & "</td>")
Response.Write ("</tr>")
Rs. MoveNext
Loop
Rs.close
Conn. Close
Set rs=nothing
Set conn=nothing%>
</table>
<% End If%>
</body>