|
 |
asp_databases thread: Newbie to ASP and Database
Message #1 by parker149@h... on Sat, 20 Oct 2001 00:45:17
|
|
I'm a self taught newbie to asp and asp database's. I have some code that
is by far not elagent but it gets the job done. I was wondering if someone
could help me with something. Here is the code from a test page that I am
working. I'm just trying to see if I can get the number of records in a
table.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Recordset Test Page</title>
</head>
<%
Dim strSQL1
Dim strConAccess
Dim objConection
Dim objrsLStbl
Dim strConnectString
Dim strMerchant
Dim strBannerLink
strSQL1 = "SELECT * FROM LinkShareMerchantList;"
strConAccess = "Driver={Microsoft Access Driver (*.mdb)};"
& "DBQ=" & Server.MapPath("../database/Parker-Sales.mdb")
Set objConection = Server.CreateObject ("ADODB.Connection")
SET objrsLStbl= Server.CreateObject ("ADODB.Recordset")
objConection.Open strConAccess
objrsLStbl.Open strSQL1, objConection
%>
<body>
<%="Record Count = " & objrsLSTbl.RecordCount & "<br>" %>
<%DO UNTIL objrsLStbl.EOF
strMerchant = objrsLStbl("Merchant")
Response.Write strMerchant & "<br>"
objrsLStbl.movenext
Loop
objrsLSTbl.Close
Set objrsLSTbl=nothing
objConection.Close
Set objConection=nothing
%>
</body>
</html>
Now when this is run it prints -1 for the record count. Why is this? Do I
have to maually loop through the recordset to get the number of records
then store that in a variable. Then proceed to do my processing of the
recordset.That would seem to be a waist of server resources. I am wanting
to use the number of records as the upper limit for a random number
generator so that I don't move beyond the last record and cause an error.
I don't want to have to hard code the number of records since it could
change on a regular basis. Also an added question. Can someone point me to
code for a random number generator?
Thanks in Advance
Seth Parker
Message #2 by Anupama Nallari <ANallari@p...> on Fri, 19 Oct 2001 23:07:21 -0500
|
|
Even I had the same problem with the recordcount property. It never works.
What I do to get consistent results is to declare an integer variable and
keep incrementing it by 1 till I reach the EOF.
I am sure you must be aware of it but that's what I do.
If anyone could shed light on why the recordcount property does this it
would be good.
Anu
-----Original Message-----
From: parker149@h... [mailto:parker149@h...]
Sent: Friday, October 19, 2001 7:45 PM
To: ASP Databases
Subject: [asp_databases] Newbie to ASP and Database
I'm a self taught newbie to asp and asp database's. I have some code that
is by far not elagent but it gets the job done. I was wondering if someone
could help me with something. Here is the code from a test page that I am
working. I'm just trying to see if I can get the number of records in a
table.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Recordset Test Page</title>
</head>
<%
Dim strSQL1
Dim strConAccess
Dim objConection
Dim objrsLStbl
Dim strConnectString
Dim strMerchant
Dim strBannerLink
strSQL1 = "SELECT * FROM LinkShareMerchantList;"
strConAccess = "Driver={Microsoft Access Driver (*.mdb)};"
& "DBQ=" & Server.MapPath("../database/Parker-Sales.mdb")
Set objConection = Server.CreateObject ("ADODB.Connection")
SET objrsLStbl= Server.CreateObject ("ADODB.Recordset")
objConection.Open strConAccess
objrsLStbl.Open strSQL1, objConection
%>
<body>
<%="Record Count = " & objrsLSTbl.RecordCount & "<br>" %>
<%DO UNTIL objrsLStbl.EOF
strMerchant = objrsLStbl("Merchant")
Response.Write strMerchant & "<br>"
objrsLStbl.movenext
Loop
objrsLSTbl.Close
Set objrsLSTbl=nothing
objConection.Close
Set objConection=nothing
%>
</body>
</html>
Now when this is run it prints -1 for the record count. Why is this? Do I
have to maually loop through the recordset to get the number of records
then store that in a variable. Then proceed to do my processing of the
recordset.That would seem to be a waist of server resources. I am wanting
to use the number of records as the upper limit for a random number
generator so that I don't move beyond the last record and cause an error.
I don't want to have to hard code the number of records since it could
change on a regular basis. Also an added question. Can someone point me to
code for a random number generator?
Thanks in Advance
Seth Parker
Message #3 by "Daniel O'Dorisio" <daniel@o...> on Sat, 20 Oct 2001 00:05:17 -0400
|
|
You are using a forward only recordset, you need to use like
adopenstatic. Change your open line to this:
objrsLStbl.Open strSQL1, objConection, adopenstatic, adlockreadonly
For more info look on Ken's site:
http://www.adopenstatic.com/faq/recordcounterror.asp really good info on
there.
daniel
--------------------------
Daniel O'Dorisio
daniel@o...
www.odorisio-networks.com
--------------------------
-----Original Message-----
From: parker149@h... [mailto:parker149@h...]
Sent: Saturday, October 20, 2001 12:45 AM
To: ASP Databases
Subject: [asp_databases] Newbie to ASP and Database
I'm a self taught newbie to asp and asp database's. I have some code
that
is by far not elagent but it gets the job done. I was wondering if
someone
could help me with something. Here is the code from a test page that I
am
working. I'm just trying to see if I can get the number of records in a
table.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Recordset Test Page</title>
</head>
<%
Dim strSQL1
Dim strConAccess
Dim objConection
Dim objrsLStbl
Dim strConnectString
Dim strMerchant
Dim strBannerLink
strSQL1 = "SELECT * FROM LinkShareMerchantList;"
strConAccess = "Driver={Microsoft Access Driver (*.mdb)};"
& "DBQ=" & Server.MapPath("../database/Parker-Sales.mdb")
Set objConection = Server.CreateObject ("ADODB.Connection")
SET objrsLStbl= Server.CreateObject ("ADODB.Recordset")
objConection.Open strConAccess
objrsLStbl.Open strSQL1, objConection
%>
<body>
<%="Record Count = " & objrsLSTbl.RecordCount & "<br>" %>
<%DO UNTIL objrsLStbl.EOF
strMerchant = objrsLStbl("Merchant")
Response.Write strMerchant & "<br>"
objrsLStbl.movenext
Loop
objrsLSTbl.Close
Set objrsLSTbl=nothing
objConection.Close
Set objConection=nothing
%>
</body>
</html>
Now when this is run it prints -1 for the record count. Why is this? Do
I
have to maually loop through the recordset to get the number of records
then store that in a variable. Then proceed to do my processing of the
recordset.That would seem to be a waist of server resources. I am
wanting
to use the number of records as the upper limit for a random number
generator so that I don't move beyond the last record and cause an
error.
I don't want to have to hard code the number of records since it could
change on a regular basis. Also an added question. Can someone point me
to
code for a random number generator?
Thanks in Advance
Seth Parker
Message #4 by "Daniel O'Dorisio" <daniel@o...> on Sat, 20 Oct 2001 00:39:44 -0400
|
|
Oh goodness.. That is terrible at performance..
I believe recordcount is terrible as well..
You know the best method (for SQL server) is
Using SELECT COUNT(*)
Look for more info on the this in Books On Line, or on here:
http://www.w3schools.com/sql/sql_count.asp
Hth
daniel
--------------------------
Daniel O'Dorisio
daniel@o...
www.odorisio-networks.com
--------------------------
-----Original Message-----
From: Anupama Nallari [mailto:ANallari@p...]
Sent: Saturday, October 20, 2001 12:07 AM
To: ASP Databases
Subject: [asp_databases] RE: Newbie to ASP and Database
Even I had the same problem with the recordcount property. It never
works. What I do to get consistent results is to declare an integer
variable and keep incrementing it by 1 till I reach the EOF.
I am sure you must be aware of it but that's what I do.
If anyone could shed light on why the recordcount property does this it
would be good.
Anu
Message #5 by "Ken Schaefer" <ken@a...> on Mon, 22 Oct 2001 12:25:09 +1000
|
|
www.adopenstatic.com/faq/recordcounterror.asp
(why .recordcount returns -1)
www.adopenstatic.com/faq/recordcountalternatives.pas
(superior alternatives to .recordcount - depending on what you need to do)
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <parker149@h...>
Subject: [asp_databases] Newbie to ASP and Database
: I'm a self taught newbie to asp and asp database's. I have some code that
: is by far not elagent but it gets the job done. I was wondering if someone
: could help me with something. Here is the code from a test page that I am
: working. I'm just trying to see if I can get the number of records in a
: table.
: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
:
: <html>
: <head>
: <title>Recordset Test Page</title>
: </head>
: <%
: Dim strSQL1
: Dim strConAccess
: Dim objConection
: Dim objrsLStbl
: Dim strConnectString
: Dim strMerchant
: Dim strBannerLink
:
: strSQL1 = "SELECT * FROM LinkShareMerchantList;"
: strConAccess = "Driver={Microsoft Access Driver (*.mdb)};"
: & "DBQ=" & Server.MapPath("../database/Parker-Sales.mdb")
: Set objConection = Server.CreateObject ("ADODB.Connection")
: SET objrsLStbl= Server.CreateObject ("ADODB.Recordset")
: objConection.Open strConAccess
: objrsLStbl.Open strSQL1, objConection
: %>
: <body>
: <%="Record Count = " & objrsLSTbl.RecordCount & "<br>" %>
: <%DO UNTIL objrsLStbl.EOF
: strMerchant = objrsLStbl("Merchant")
: Response.Write strMerchant & "<br>"
: objrsLStbl.movenext
: Loop
: objrsLSTbl.Close
: Set objrsLSTbl=nothing
: objConection.Close
: Set objConection=nothing
: %>
: </body>
: </html>
: Now when this is run it prints -1 for the record count. Why is this? Do I
: have to maually loop through the recordset to get the number of records
: then store that in a variable. Then proceed to do my processing of the
: recordset.That would seem to be a waist of server resources. I am wanting
: to use the number of records as the upper limit for a random number
: generator so that I don't move beyond the last record and cause an error.
: I don't want to have to hard code the number of records since it could
: change on a regular basis. Also an added question. Can someone point me to
: code for a random number generator?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Message #6 by "Tomm Matthis" <matthis@b...> on Mon, 22 Oct 2001 11:54:35 -0400
|
|
The recordcount property *does* work. You have to use a clientside cursor and
specify the correct type of recordset that supports the recordcount.
Alternatively, with the code you're using now, if you open the recordset then
do a rs.movelast, the .recordcount will then have the correct count. (No need
to set up your own counter then.)
-- Tomm
> -----Original Message-----
> From: Anupama Nallari [mailto:ANallari@p...]
> Sent: Saturday, October 20, 2001 12:07 AM
> To: ASP Databases
> Subject: [asp_databases] RE: Newbie to ASP and Database
>
>
> Even I had the same problem with the recordcount property. It never works.
> What I do to get consistent results is to declare an integer variable and
> keep incrementing it by 1 till I reach the EOF.
>
> I am sure you must be aware of it but that's what I do.
>
> If anyone could shed light on why the recordcount property does this it
> would be good.
>
> Anu
>
> -----Original Message-----
> From: parker149@h... [mailto:parker149@h...]
> Sent: Friday, October 19, 2001 7:45 PM
> To: ASP Databases
> Subject: [asp_databases] Newbie to ASP and Database
>
>
> I'm a self taught newbie to asp and asp database's. I have some code that
> is by far not elagent but it gets the job done. I was wondering if someone
> could help me with something. Here is the code from a test page that I am
> working. I'm just trying to see if I can get the number of records in a
> table.
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>
> <html>
> <head>
> <title>Recordset Test Page</title>
> </head>
> <%
> Dim strSQL1
> Dim strConAccess
> Dim objConection
> Dim objrsLStbl
> Dim strConnectString
> Dim strMerchant
> Dim strBannerLink
>
> strSQL1 = "SELECT * FROM LinkShareMerchantList;"
> strConAccess = "Driver={Microsoft Access Driver (*.mdb)};"
> & "DBQ=" & Server.MapPath("../database/Parker-Sales.mdb")
> Set objConection = Server.CreateObject ("ADODB.Connection")
> SET objrsLStbl= Server.CreateObject ("ADODB.Recordset")
> objConection.Open strConAccess
> objrsLStbl.Open strSQL1, objConection
> %>
> <body>
> <%="Record Count = " & objrsLSTbl.RecordCount & "<br>" %>
> <%DO UNTIL objrsLStbl.EOF
> strMerchant = objrsLStbl("Merchant")
> Response.Write strMerchant & "<br>"
> objrsLStbl.movenext
> Loop
> objrsLSTbl.Close
> Set objrsLSTbl=nothing
> objConection.Close
> Set objConection=nothing
> %>
> </body>
> </html>
> Now when this is run it prints -1 for the record count. Why is this? Do I
> have to maually loop through the recordset to get the number of records
> then store that in a variable. Then proceed to do my processing of the
> recordset.That would seem to be a waist of server resources. I am wanting
> to use the number of records as the upper limit for a random number
> generator so that I don't move beyond the last record and cause an error.
> I don't want to have to hard code the number of records since it could
> change on a regular basis. Also an added question. Can someone point me to
> code for a random number generator?
>
> Thanks in Advance
>
> Seth Parker
>
> $subst('Email.Unsub')
>
>
|
|
 |