当前位置: 网学 > 编程文档 > ASP > 正文

asp中记录集对象的getrows和getstring用法分析

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/16
n(valPrefix) )

Response.Write "<Select ...>" & vbNewLine
Response.Write valPrefix & opts
Response.Write "</Select>"
%>

如果想建立一个正确的表格的话,解决那个BUG,只要这样做就可以了:
复制代码 代码如下:
<%
Set RS = conn.Execute("Select * FROM table")
tdSuffix = "</TD>" & vbNewLine & "<TD>
trPrefix = "<TR>" & vbNewLine & "<TD>"
trSuffix = "</TD>" & vbNewLine & "</TR>" & vbNewLine & "<TR>" & vbNewLine
opts = RS.GetString( , , tdSuffix, trSuffix & trPrefix, "--error--" )
'' Next line is the key to it!
opts = Left( opts, Len(opts)-Len(trPrefix) )
Response.Write "<TABLE Border=1 CellPadding=5>" & vbNewLine
Response.Write trPrefix & opts
Response.Write "</TABLE>" & vbNewLine
%>

再介绍一个完全不同的办法:
复制代码 代码如下:
<%
SQL = "Select ''<OPTION Value='''''',value,''''''>'',text,''</OPTION>'' FROM table orDER BY text"
Set RS = conn.Execute(SQL)
Response.Write "<Select>" & vbNewLine & RS.GetString(,,"",vbNewLine) & "</Select>"
%>

你用过吗。。。

看到了吗?可以直接从查询中返回结果。
再进一步,您可以这样做:
复制代码 代码如下:
<%
SQL = "Select ''<OPTION Value='''''' & value & ''''''>'' & text & ''</OPTION>'' FROM table orDER BY text"
Set RS = conn.Execute(SQL)
Response.Write "<Select>" & vbNewLine & RS.GetString(,,"",vbNewLine) & "</Select>"
%>

下面是一份完整的示例:
Script Output:
711855 Wednesday 23 3/23/2005 1:33:37 AM
711856 Wednesday 23 3/23/2005 1:23:00 AM
711857 Wednesday 23 3/23/2005 1:26:34 AM
711858 Wednesday 23 3/23/2005 1:33:53 AM
711859 Wednesday 23 3/23/2005 1:30:36 AM

ASP完整代码如下:
复制代码 代码如下:
<%
'' Selected constants from adovbs.inc:
Const adClipString = 2

'' Declare our variables... always good practice!
Dim cnnGetString '' ADO connection
Dim rstGetString '' ADO recordset
Dim strDBPath '' Path to our Access DB (*.mdb) file
Dim strDBData '' String that we dump all the data into
Dim strDBDataTable '' String that we dump all the data into
'' only this time we build a table
'' MapPath to our mdb file''s physical path.
strDBPath = Server.MapPath("db_scratch.mdb")

'' Create a Connection using OLE DB
Set cnnGetString = Server.CreateObject("ADODB.Connection")

'' This line is for the Access sample database:
''cnnGetString.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
'' We''re actually using SQL Server so we use this line instead.
'' Comment this line out and uncomment the Access one above to
'' play with the script on your own server.
cnnGetString.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _
& "Initial Catalog=samples;User Id=samples;Password=password;" _
& "Connect Timeout=15;Network Library=dbmssocn;"

'' Execute a simple query using the connection object.
'' Store the resulting recordset in our variable.
Set rstGetString = cnnGetString.Execute("Select * FROM scratch")

'' Now this is where it gets interesting... Normally we''d do
'' a loop of some sort until we r

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号