木子屋 Dnawo's BLOG

ASP使用Set ors=oConn.Execute()时获取记录数的方法

👤 dnawo 📅 2010-10-28 👁 5036 👍 0 💬 0 🔄 来源:本站原创
在ASP中,如果你使用Set ors=oConn.Execute()来创建RecordSet对象,再使用RecordSet.RecordCount获取记录数时,你会发现它的值为-1,这时,我们可以使用GetRows方法来获取记录数:

<%
Dim oConn, ors, aRows
Dim i,j
Set oConn=Server.CreateObject("ADODB.Connection")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database/newasp.resx")
Set ors=oConn.Execute("Select TOP 5 SoftID,SoftName FROM NC_SoftList")
Response.Write "RecordCount:" & ors.RecordCount & "<br/>" '-1
aRows=oRs.GetRows(-1) 'oRs.Eof=True,aRows(col,row)
Set ors=Nothing
oConn.Close()
Set oConn=Nothing

If IsArray(aRows) Then
	[color=Red]Response.Write "RecordCount:" & UBound(aRows,2)+1 & "<br/>"[/color]
	For i=0 To UBound(aRows,2)
		For j=0 To UBound(aRows,1)
			Response.Write aRows(j,i)
			If j<> UBound(aRows,1) Then Response.Write ","
		Next
		Response.Write "<br/>"
	Next
End If
%>

评论(0)

暂无评论。

验证码
评论需审核通过后显示
← 上一篇 新云CMS4.0SP2标签解析顺序 下一篇 → 大幅度提升WinRAR解压速度的方法