JElster
asked on
ASP - Record count from SQL Server
The following returns a Count of -1 when connecting to SQL Server 2005.
It should return 10. What's wrong with this code.
thx
<%
Response.Write("Hello")
set conn=Server.CreateObject(" ADODB.Conn ection")
conn.Open "Provider=sqloledb;Data Source=myDB;Initial Catalog=Cust;UID=Auser;PWD =auser;con nect timeout=30"
set rs=Server.CreateObject("AD ODB.record set")
sql="SELECT top 10 * from Customers"
rs.Open sql,conn
if rs.Supports(adApproxPositi on)=true then
i=rs.RecordCount
response.write("<BR> The number of records is: " & i)
end if
rs.Close
conn.Close
%>
It should return 10. What's wrong with this code.
thx
<%
Response.Write("Hello")
set conn=Server.CreateObject("
conn.Open "Provider=sqloledb;Data Source=myDB;Initial Catalog=Cust;UID=Auser;PWD
set rs=Server.CreateObject("AD
sql="SELECT top 10 * from Customers"
rs.Open sql,conn
if rs.Supports(adApproxPositi
i=rs.RecordCount
response.write("<BR> The number of records is: " & i)
end if
rs.Close
conn.Close
%>
ASKER
I get
Microsoft OLE DB Provider for SQL Server error '80040e24'
Rowset does not support fetching backward.
Microsoft OLE DB Provider for SQL Server error '80040e24'
Rowset does not support fetching backward.
rs.Open sql,conn
if not rs.bof or not rs.eof then
myArray=rs.getrows() ' fast
end if
rs.Close
conn.Close
counter=0
' now you have an array and don't have to call the database
For r = LBound(myArray, 2) To UBound(myArray, 2)
name = arrZips(0, r)
address= arrZips(1, r)
city= arrZips(2, r)
zip= arrZips(3, r)
counter=counter+1
response.write "Name "&name & " record count "&counter&"<br>"
next
response.write "You have "&counter& " records"
if not rs.bof or not rs.eof then
myArray=rs.getrows() ' fast
end if
rs.Close
conn.Close
counter=0
' now you have an array and don't have to call the database
For r = LBound(myArray, 2) To UBound(myArray, 2)
name = arrZips(0, r)
address= arrZips(1, r)
city= arrZips(2, r)
zip= arrZips(3, r)
counter=counter+1
response.write "Name "&name & " record count "&counter&"<br>"
next
response.write "You have "&counter& " records"
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if rs.Supports(adApproxPositi
rs.MoveLast
rs.MoveFirst
i=rs.RecordCount
response.write("<BR> The number of records is: " & i)
end if