PDA

View Full Version : چطور تعداد رکوردها رو بدونم؟



پرنده کوچک
یک شنبه 22 خرداد 1384, 11:50 صبح
سلام.
چطوری از دیتابیسم یه count بگیرم تا بدونم چند تا رکورد توش هست؟
بدون اینکه مجبور بشم همه رکوردها رو بخونم.

Nightbat
دوشنبه 23 خرداد 1384, 09:21 صبح
اگر ADO وصل بشی می تونی از recordcount استفاده کنی ، یادت باشه که حتما باید از Dynamic keyset استفاده کنی! :sunglass:

Yoosha
یک شنبه 07 آبان 1385, 17:15 عصر
<!-- #INCLUDE FILE="./download/adovbs.inc" -->
<%

Dim DB_CONNSTRING
DB_CONNSTRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("./db_scratch.mdb") & ";"

DB_CONNSTRING = "Provider=SQLOLEDB;Data Source=10.2.1.214;" _
& "Initial Catalog=samples;User Id=samples;Password=password;" _
& "Connect Timeout=15;Network Library=dbmssocn;"

%>

<%
Dim rsCount

Set rsCount = Server.CreateObject("ADODB.Recordset")


rsCount.Open "scratch", DB_CONNSTRING, adOpenStatic, adLockReadOnly, adCmdTable


Response.Write "<p>This table currently has <strong><font color=""#FF0000"">"
Response.Write rsCount.RecordCount ' This is the line that does it!
Response.Write "</font></strong> records in it!</p>" & vbCrLf

If LCase(Request.QueryString("showtable")) = "true" Then
Dim Field
Dim bColor
bColor = False


Response.Write "<p>They are:</p>" & vbCrLf


Response.Write "<table border=""1"">" & vbCrLf


Response.Write vbTab & "<tr>" & vbCrLf
For Each Field in rsCount.Fields
Response.Write vbTab & vbTab & "<td bgcolor=""#CCCCCC""><strong>" & Field.Name & "</strong></td>" & vbCrLf
Next
Response.Write vbTab & "</tr>" & vbCrLf


Do While Not rsCount.EOF
Response.Write vbTab & "<tr>" & vbCrLf
For Each Field in rsCount.Fields
Response.Write vbTab & vbTab & "<td bgcolor="""


If bColor Then
Response.Write "#CCCCFF" ' Light blueish
Else
Response.Write "#FFFFFF" ' White
End If

Response.Write """>" & Field.Value & "</td>" & vbCrLf
Next
Response.Write vbTab & "</tr>" & vbCrLf


bColor = Not bColor
rsCount.MoveNext
Loop


Response.Write "</table>" & vbCrLf
Response.Write "<p><a href=""db_count.asp"">Hide the table</a></p>" & vbCrLf
Else
Response.Write "<p><a href=""db_count.asp?showtable=true"">Show the table</a></p>" & vbCrLf
End If


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