当Recordcount返回-1时怎样计算记录数目(转)

' BEGIN CONSTANT DEFINITION

' The following command includes the ADODB VBScript
constants file.
' If you can't find your copy you can download a copy from:
' http://www.asp101.com/samples/download/adovbs.inc
' It may not be the most recent copy so use it at your own
risk.

%>
<!-- #INCLUDE FILE="./download/adovbs.inc" --&gt

' DB Configuration variables
' After this, strictly used as if it were a Const.
Dim DB_CONNSTRING
DB_CONNSTRING = "DRIVER={Microsoft Access Driver
(*.mdb)};DBQ=" & Server.Mappath("./db_scratch.mdb") & ";"

' Now we override the above setting so the sample uses our
SQL server.
' Comment out the following line to use the sample Access
DB.
DB_CONNSTRING = Application("SQLConnString") & _
"UID=" & Application("SQLUsername") & ";" & _
"PWD=" & Application("SQLPassword") & ";"

' END CONSTANT DEFINITION
%>

Dim rsCount ' The recordset object

' Create an instance of an ADO Recordset
Set rsCount = Server.CreateObject("ADODB.Recordset")

' Open RS
' I'm actually doing this directly (without a connection object) to
keep
' the code short and to the point. I'm opening the RS with a static
' cursor, read only, and telling it that "scratch" is a table name and
' not a SQL command. If I don't specify how to open the rs, I'd get
the
' default cursor type which doesn't support .RecordCount!
rsCount.Open "scratch", DB_CONNSTRING, adOpenStatic, adLockReadOnly,
adCmdTable

' Show RecordCount
' I dress it up and pop it into the middle of a sentence, but you can
' do whatever you want with it.
Response.Write "This table currently has "
Response.Write rsCount.RecordCount ' This is the line that does it!
Response.Write "
records in it!
" & vbCrLf


'=====================================================================
=
' BEGIN TABLE DISPLAY
' Now I'm going to display the table if they requested it just so you
' have something to look at! This really doesn't pertain to the topic
' of this sample so I'm going to keep the code short but feel free to
' look it over and if you do please notice the pretty HTML it outputs!
' Ugly HTML output is a pet peeve of mine! ;)
If LCase(Request.QueryString("showtable")) = "true" Then
Dim Field ' Field Looper for display
Dim bColor ' Use for showing alternating colors
bColor = False

' Spacers and intro
Response.Write "
" & vbCrLf & "They are:
" & vbCrLf
& "
" & vbCrLf

' Start the table
Response.Write "

' Write Titles
Response.Write vbTab & "

" & vbCrLf
For Each Field in rsCount.Fields
Response.Write vbTab & vbTab & "BGCOLOR=""#CCCCCC""> " & Field.Name & "" & vbCrLf
Next 'Field
Response.Write vbTab & "" & vbCrLf

' Loop through records outputting data
Do While Not rsCount.EOF
Response.Write vbTab & "

" & vbCrLf
For Each Field in rsCount.Fields
Response.Write vbTab & vbTab & "BGCOLOR="""

' Decide what color to output
If bColor Then
Response.Write "#CCCCFF" '
Light blueish
Else
Response.Write "#FFFFFF" ' White
End If

Response.Write """>" & Field.Value
& "" & vbCrLf
Next 'Field
Response.Write vbTab & "

" & vbCrLf

' Toggle our colors
bColor = Not bColor
rsCount.MoveNext
Loop

' End the table
Response.Write "

" & vbCrLf
Response.Write "
Hide the
table
" & vbCrLf
Else
Response.Write "
showtable=true"">Show the table" & vbCrLf
End If
' END TABLE DISPLAY - Now back to our regularly scheduled code!
'=====================================================================
=

' Close and dispose of recordset object
rsCount.Close
Set rsCount = Nothing
%>


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-124471/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-124471/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值