473,394 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Do Until Loop problem

I am trying to display records from a recordset after sql statement:

<% sqlstr ="SELECT horsename FROM tblhorseentry WHERE trackname = '" &
request.querystring("trackname") & "' and racedate = '" &
request.querystring("racedate");"
Set rs1 = Server.CreateObject("ADODB.Recordset")

rs1.Open sqlstr,pConn,3

do until rs1.eof

response.write left(rs1("horsename"),14)

rno = rno + 1
rtg = rtg + 1

rs1.Close
set rs1 = nothing
loop %>

...but when I test the querystring link going into the page with the asp
scripting, I do not see my horsename(s) display; it just echoes a blank
webpage

??
E.M.

Jul 22 '05 #1
4 5812

".Net Sports" <ba********@cox.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I am trying to display records from a recordset after sql statement:

<% sqlstr ="SELECT horsename FROM tblhorseentry WHERE trackname = '" &
request.querystring("trackname") & "' and racedate = '" &
request.querystring("racedate");"
Set rs1 = Server.CreateObject("ADODB.Recordset")

rs1.Open sqlstr,pConn,3

do until rs1.eof

response.write left(rs1("horsename"),14)

rno = rno + 1
rtg = rtg + 1

rs1.Close
set rs1 = nothing
loop %>

..but when I test the querystring link going into the page with the asp
scripting, I do not see my horsename(s) display; it just echoes a blank
webpage

??
E.M.


You are destroying the recordset rs1 before calling loop. You are also
missing the movenext method. I'm also assuming that you want a line break
between each horse name, so I've included one in the response.write. If you
just want a space, substitute <br> for &nbsp;

Try this:

<%
sqlstr ="SELECT horsename FROM tblhorseentry WHERE trackname = '" &
request.querystring("trackname") & "' and racedate = '" &
request.querystring("racedate");"

Set rs1 = pConn.execute(sqlstr)

do until rs1.eof
response.write left(rs1("horsename"),14) & "<br>"
rs1.movenext
loop

rs1.close : set rs1 = nothing
%>

Morris
Jul 22 '05 #2
..Net Sports wrote:
I am trying to display records from a recordset after sql statement:

<% sqlstr ="SELECT horsename FROM tblhorseentry WHERE trackname = '"
& request.querystring("trackname") & "' and racedate = '" &
request.querystring("racedate");"
Set rs1 = Server.CreateObject("ADODB.Recordset")

rs1.Open sqlstr,pConn,3

do until rs1.eof

response.write left(rs1("horsename"),14)

rno = rno + 1
rtg = rtg + 1

rs1.Close
set rs1 = nothing
loop %>

..but when I test the querystring link going into the page with the
asp scripting, I do not see my horsename(s) display; it just echoes a
blank webpage

??
E.M.


Morris corrected your code. Here's a security and performance tip:

dim pConn, rs, cmd, arData, arParms,sqlstr, i
arParms=Array(request.querystring("trackname"), _
request.querystring("racedate"))

sqlstr ="SELECT horsename FROM tblhorseentry " & _
WHERE trackname = ? and racedate = ?"

'initialize and open pconn, then

Set cmd=createobject("adodb.command")
cmd.commandtype=1
cmd.commandtext=sqlstr
Set cmd.activeconnection=pConn
Set rs = cmd.Execute(,arParms)

if not rs.EOF then arData=rs.GetRows
rs.Close: Set rs=nothing
pConn.close: set pConn=nothing

if isArray(arData) then
for i = 0 to ubound(arData,2)
response.write left(arData(0,i),14)
rno = rno + 1
rtg = rtg + 1
next
else
response.Write "No records returned"
end if
HTH,
Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #3

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:eB*************@TK2MSFTNGP15.phx.gbl...
.Net Sports wrote:
I am trying to display records from a recordset after sql statement:

<% sqlstr ="SELECT horsename FROM tblhorseentry WHERE trackname = '"
& request.querystring("trackname") & "' and racedate = '" &
request.querystring("racedate");"
Set rs1 = Server.CreateObject("ADODB.Recordset")

rs1.Open sqlstr,pConn,3

do until rs1.eof

response.write left(rs1("horsename"),14)

rno = rno + 1
rtg = rtg + 1

rs1.Close
set rs1 = nothing
loop %>

..but when I test the querystring link going into the page with the
asp scripting, I do not see my horsename(s) display; it just echoes a
blank webpage

??
E.M.


Morris corrected your code. Here's a security and performance tip:

dim pConn, rs, cmd, arData, arParms,sqlstr, i
arParms=Array(request.querystring("trackname"), _
request.querystring("racedate"))

sqlstr ="SELECT horsename FROM tblhorseentry " & _
WHERE trackname = ? and racedate = ?"

'initialize and open pconn, then

Set cmd=createobject("adodb.command")
cmd.commandtype=1
cmd.commandtext=sqlstr
Set cmd.activeconnection=pConn
Set rs = cmd.Execute(,arParms)

if not rs.EOF then arData=rs.GetRows
rs.Close: Set rs=nothing
pConn.close: set pConn=nothing

if isArray(arData) then
for i = 0 to ubound(arData,2)
response.write left(arData(0,i),14)
rno = rno + 1
rtg = rtg + 1
next
else
response.Write "No records returned"
end if


I must start using parameter queries. In the meantime, 2 questions:

1. Why do you test to see if arData is an array? Won't it be an array if rs
is not EOF? and
2. Where's the End If to close off if not rs.EOF...?

TIA

Morris
Jul 22 '05 #4
Morris wrote:

Morris corrected your code. Here's a security and performance tip:

dim pConn, rs, cmd, arData, arParms,sqlstr, i
arParms=Array(request.querystring("trackname"), _
request.querystring("racedate"))

sqlstr ="SELECT horsename FROM tblhorseentry " & _
WHERE trackname = ? and racedate = ?"

'initialize and open pconn, then

Set cmd=createobject("adodb.command")
cmd.commandtype=1
cmd.commandtext=sqlstr
Set cmd.activeconnection=pConn
Set rs = cmd.Execute(,arParms)

if not rs.EOF then arData=rs.GetRows
rs.Close: Set rs=nothing
pConn.close: set pConn=nothing

if isArray(arData) then
for i = 0 to ubound(arData,2)
response.write left(arData(0,i),14)
rno = rno + 1
rtg = rtg + 1
next
else
response.Write "No records returned"
end if
I must start using parameter queries.


Yes, you must. ;-)
In the meantime, 2 questions:

1. Why do you test to see if arData is an array? Won't it be an array
if rs is not EOF? and
Yes. But it will not be an array if rs IS EOF.
It only gets defined as an array in the If statement: i.e., when rs.EOF is
false.

See? It gets dimmed as a variant:
Dim arData
So it is not yet an array.
It gets "converted to" an array in this statement:
if not rs.EOF then arData=rs.GetRows

So, if rs.EOF is true, it remains a variant.

My goal is to close and destroy the ADO objects as soon as I possibly can,
as well as reduce the lines of code I write, which is why I do not do this:

if not rs.eof then
arData=rs.getrows
rs.close:set rs=nothing
pConn.close: set pConn=nothing
for i = 0 to ...
else
rs.close:set rs=nothing
pConn.close: set pConn=nothing
response.Write "No records returned"
end if
2. Where's the End If to close off if not rs.EOF...?


In vbscript/VB/VBA, there are two versions of If...Then:

1. A single-line version which I used in my example. It should consist
solely of
If <expression> Then <action if true>

However, a bug in vbscript allows this to be used:
If <expression> Then <action if true> Else <action if false> End if
In VB/VBA, this would raise an error.

2. And the multi-line version which you are used to:
If <expression> then
<action if true>
{ElseIf <expression> Then
<action if true>}
Else
<action if false>
End if

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Eric | last post by:
Let me start off by saying I have VB working model which means no help. I have searched MSDN. It seems that I get "Read the help" instead of answers which is totally useless to me. With that...
9
by: deko | last post by:
When doing a mail merge with Word, I can't seem to get the below (abbreviated) routine to iterate strBookmark01 -- it just uses the first name in the recordset for all 10 (or whatever) documents......
1
by: googlinggoogler | last post by:
Hi, Sorry for the poor topic name, i couldnt think how to word it any better. I have put below my code and I hope this makes what im trying to say, easier to understand. (I realise that the...
3
by: peter.meth | last post by:
Hi All, I am making a file manager type of application and am trying to duplicate Windows Explorer's behaviour when copying files; ie, display a second form with the copy files animation. As it...
7
by: Thomas Nelson | last post by:
Occasionally someone posts to this group complaining about the lack of "repeat ... until" in python. I too have occasionally wished for such a construct, and after some thinking, I came up with...
4
kirubagari
by: kirubagari | last post by:
Private Sub cmdscan_Click() Const a As Byte = 4 Const b As Byte = &HFF Dim I As Long Dim AnyChanged As Boolean Dim changeMade As Boolean Dim value As Byte 'Dim x 'Dim tmp As...
2
by: shogot99 | last post by:
Till here the info gotten is ok Loop Until strainfo = "" ScreenMNS.WaitHostQuiet (400) Second process Copy "B" & paste in "E" Range("B2:B600").Select
2
by: Constantine AI | last post by:
Hello, i am wanting a Loop procedure to check details of all the multiple rows with the following D-LOOKUP procedures; StkID.Value = DLookup("", "stkmas", " = Forms!!") Price.Value = DLookup("",...
5
by: dbrother | last post by:
Access 2003 Win XP Pro SP3 Using SQL /ADO Recordsets in a Do Loop Hello, I'm using a random number generator based on an integer input from a user from a form that will get X number of random...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.