Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Do Until Loop problem

Reply
Thread Tools

Do Until Loop problem

 
 
.Net Sports
Guest
Posts: n/a
 
      02-25-2005
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.

 
Reply With Quote
 
 
 
 
Morris
Guest
Posts: n/a
 
      02-25-2005

".Net Sports" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      02-25-2005
..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.


 
Reply With Quote
 
Morris
Guest
Posts: n/a
 
      02-25-2005

"Bob Barrows [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> .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


 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      02-25-2005
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
loop until two doubles differ by 0.00001 yogi_bear_79 C++ 2 03-11-2008 02:34 AM
loop until keypress (Windows XP) placid Python 6 08-10-2006 11:06 PM
Loop until condition is true Remi Villatel Python 40 06-23-2005 07:21 PM
Do Until Loop problem .Net Sports ASP General 0 02-25-2005 07:28 PM



Advertisments