网络学院 w3pop社区 网络资源 IT新闻

w3pop.com :: 网络学院 :: ADO :: ADO查询语句

会员登陆

帐号

密码

回答

记住密码

忘记密码? 注册

ADO
ADO DataTypes
ADO 摘要
ADO 实例

ADO查询语句


作者:w3pop.com 翻译/整理:w3pop.com 发布:2007-04-28 浏览:4546 :: ::

We may use SQL to create queries to specify only a selected set of records and fields to view.
我们可以使用SQL来创建查询语句,让它仅对具有指定属性的记录和字段进行查找。


Examples
案例

Display records where "Companyname" starts with an A
显示“Companyname”中以“A”为首的记录:
How to display only the records from the "Customers" table that have a "Companyname" that starts with an A.
如何仅对"Customers"表中以“A”为首的“Companyname” 记录进行显示。

Display records where "Companyname" is > E
显示"Companyname" > E的记录
How to display only the records from the "Customers" table that have a "Companyname" that is larger than E.
如何仅对"Customers"表中以 “Companyname” 大于E的记录进行显示。

Display only Spanish customers
仅显示西班牙客户[Spanish customers]
How to display only the Spanish customers from the "Customers" table.
如何仅对"Customers"表中西班牙客户[Spanish customers]的记录进行显示。

Let the user choose filter
让用户进行自主选择
Let the user choose which country to show customers from.
让用户自行选择国家名,并显示出该国所对应的客户。


Display Selected Data
显示指定的数据

We want to display only the records from the "Customers" table that have a "Companyname" that starts with an A (remember to save the file with an .asp extension):
我们希望仅对"Customers"表中以“A”为首的“Companyname” 记录进行显示,具体代码如下(记住:使用“.asp”扩展名保存文件):

<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>

Here is the result:
输出结果:

Companyname Contactname
Alfreds Futterkiste Maria Anders

评论 (0) All