当前位置: 首页 > 网络学院 > 服务端脚本教程 > ADO > ADO查询语句

ADO
ADO介绍
ADO数据库连接
ADO记录集
ADO显示记录
ADO查询语句
ADO记录排序
ADO添加记录
ADO更新记录
ADO删除记录
ADO演示
ADO提升执行速度
ADO Command对象
ADO Connection对象
ADO Error
ADO Field
ADO Parameter
ADO 属性
ADO Record
ADO Recordset
ADO Stream

ADO 中的 ADO查询语句


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 1128 ::
收藏到网摘: n/a

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

评论 (1) 1 All

登陆 | 还没注册?