阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      ADO 查询

      ADO 查询

      我们可以使用 SQL 来创建查询,这样就可以指定仅查看选定的记录和字段。

      显示选定的数据

      我们希望仅仅显示 “Customers” 表的 “Companyname” 字段中以 A 开头的记录:

      <html>
      <body>
      
      <%
      set conn=Server.CreateObject("ADODB.Connection")
      conn.Provider="Microsoft.Jet.OLEDB.4.0"
      conn.Open "c:/webdata/northwind.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>
      </html>
      

      显示 “Companyname” 大于 E 的记录

      如何仅仅显示 “Customers” 表的 “Companyname” 字段中大于 E 的记录。

      
      <html>
      <body>
      
      <%
      set conn=Server.CreateObject("ADODB.Connection")
      conn.Provider="Microsoft.Jet.OLEDB.4.0"
      conn.Open(Server.Mappath("/db/northwind.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>
      </html>
      

      仅显示西班牙的客户

      如何仅仅显示 “Customers” 表中的西班牙客户。

      
      <html>
      <body>
      
      <%
      set conn=Server.CreateObject("ADODB.Connection")
      conn.Provider="Microsoft.Jet.OLEDB.4.0"
      conn.Open(Server.Mappath("/db/northwind.mdb"))
      set rs = Server.CreateObject("ADODB.recordset")
      sql="SELECT Companyname, Contactname FROM Customers WHERE Country='China'"
      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>
      </html>
      

      让用户来选择筛选标准

      让用户根据国别来选择客户

      
      <html>
      <body>
      
      <%
      set conn=Server.CreateObject("ADODB.Connection")
      conn.Provider="Microsoft.Jet.OLEDB.4.0"
      conn.Open(Server.Mappath("/db/northwind.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">
      Choose 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 customers">
      </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>Companyname</th>
           <th>Contactname</th>
           <th>Country</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>
      </html>
      
      卖前端学习教程

      只需几十元,就能买到培训班的内部教程!开启高薪之路!

      零基础小白阿里P7的教程都有!

      同时长期收购所有培训班的前端教程

      目录
      目录