Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in looping with rs.... 1

Status
Not open for further replies.

cawi17

IS-IT--Management
Oct 25, 2002
18
0
0
MY


Hi guyz... I'm back with another problem.... I'm using the codes to display all record from a table...

<%

Dim cn
Dim rs
Dim sqlstring

Dim theSubject
Dim theContent
Dim theCategory

Set cn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.RecordSet")


dataConn= "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("cd2buy.mdb")
cn.open dataConn

sqlstring = "SELECT * FROM FORUM WHERE (((FORUM.Forum_ID)="& Request("threadid") &")) OR (((FORUM.Parent)='"& Request("threadid") &"'))"

rs.Open sqlstring,cn



if rs.BOF = True And rs.EOF = True Then
Response.Write ("Thread Not Found !!!! ")
else


do until rs.EOF

theCategory = rs("Category")
theSubject= rs("Subject")
theContent = rs("Content")

Response.Write("Subject is :" & theSubject)

Response.Write("<tr><font size=" & chr(34) & "4" & chr(34) &" face="& chr(34) & "Arial, Helvetica, sans-serif"& chr(34) & "><strong>" & rs("Category") & "</strong></font><br><br></tr> ")

Response.Write("<tr> <td width= "& chr(34) & "125" & chr(34) & " rowspan=" & chr(34) & "2" & chr(34) & " align="& chr(34) & "center"& chr(34) &" valign="& chr(34) & "middle"& chr(34) & " bgcolor=" & chr(34) & "#9999FF" & chr(34) & "> <font color="& chr(34) & "#FFFFFF" & chr(34) & " size="& chr(34) & "2"& chr(34) &" face="& chr(34) & "Arial, Helvetica, sans-serif"& chr(34) & "><strong>by : " & rs("UserName") & "</strong></font><font size="& chr(34) & "2"& chr(34) &" face="& chr(34) &"Arial, Helvetica, sans-serif"& chr(34) & "><br><br><font color="& chr(34) & "#FFFFFF"& chr(34) &"><strong>Date:</strong> " & rs("Date") & "</font><br><font color="& chr(34) & "#FFFFFF" & chr(34) & "><strong>Time:</strong> " & rs("Time") & "</font></font></td><td width="& chr(34) & "559"& chr(34) & " height="& chr(34) & "39"& chr(34) & "><font color="& chr(34) & "#CCCC33" & chr(34) & "><strong><em><u>Subject : " & theSubject & "</strong></font></u></em></td></tr><tr><td bgcolor=" & chr(34) & "#CCCCFF" & chr(34) & "><font size="& chr(34) & "2" & chr(34) & " face=" & chr(34) & "Geneva, Arial, Helvetica, sans-serif"& chr(34) & ">" & theContent & "</font></td></tr>")

Response.Write("This is the subject :" & rs("Forum_ID"))

rs.Movenext
loop


end if


%>



but it gives me an error...

Error Type:
ADODB.Field (0x80020009)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/cd2buy/viewthread.asp


any idea to solve the problem.....?...


Thank you...

cawi17

 
This isn't the answer you're looking for, but it's worth noting that this line:
Code:
sqlstring = "SELECT * FROM FORUM WHERE (((FORUM.Forum_ID)="& Request("threadid") &")) OR (((FORUM.Parent)='"& Request("threadid") &"'))"
can be simplified to this:
Code:
sqlstring = "SELECT * FROM FORUM WHERE Forum_ID = " & Request("threadid") & " OR Parent = '" & Request("threadid") & "'"
and mean exactly the same thing.

Also, in your two comparisons (to Forum_ID and Parent), one uses single quotes to identify the threadid as a string, the other does not. Odds are you mean this:
Code:
sqlstring = "SELECT * FROM FORUM WHERE Forum_ID = " & Request("threadid") & " OR Parent = " & Request("threadid")
with no single quotes at all.

That doesn't explain why your If isn't catching the problem, though. Still, it's worth noting that you should be able to find out if you have an empty recordset with just:
Code:
if rs.EOF Then
instead of:
Code:
if rs.BOF = True And rs.EOF = True Then
 
Hi ChrisHirst(My saviour)... It's you again.....

That was it... After a few more while revising the codes, than I thought of the same thing..... actually the error was after the codes... when I retrieve the record using the rs again on the seperate block....

I solve the problem..... verry verry silly.... silly me...

btw, thanks Genimuse for the tips..... Now u know how lazy I am...... still I'll change them later... thanx again....

Thanks again guyz....

cawi17
 
Hey cawi17 have you ever considered using a single quote instead of chr(34) that big mess has to give you a headache.


www.sitesd.com
ASP WEB DEVELOPMENT
 
Or just double double-quotes, which GREATLY simplifies it and leaves the correct syntax, changing this:
Code:
Response.Write("<tr> <td width= "& chr(34) & "125" & chr(34) & " rowspan=" & chr(34) & "2" & chr(34) & " align="& chr(34) & "center"& chr(34) &" valign="& chr(34) & "middle"& chr(34) & " bgcolor=" & chr(34) & "#9999FF" & chr(34) & "> <font color="& chr(34) & "#FFFFFF" & chr(34) & " size="& chr(34) & "2"& chr(34) &" face="& chr(34) & "Arial, Helvetica, sans-serif"& chr(34) & "><strong>by : " & rs("UserName") & "</strong></font><font size="& chr(34) & "2"& chr(34) &" face="& chr(34) &"Arial, Helvetica, sans-serif"& chr(34) & "><br><br><font color="& chr(34) & "#FFFFFF"& chr(34) &"><strong>Date:</strong> " & rs("Date") & "</font><br><font color="& chr(34) & "#FFFFFF" & chr(34) & "><strong>Time:</strong> " & rs("Time") & "</font></font></td><td width="& chr(34) & "559"& chr(34) & " height="& chr(34) & "39"& chr(34) & "><font color="& chr(34) & "#CCCC33" & chr(34) & "><strong><em><u>Subject : " & theSubject & "</strong></font></u></em></td></tr><tr><td bgcolor=" & chr(34) & "#CCCCFF" & chr(34) & "><font size="& chr(34) & "2" & chr(34) & " face=" & chr(34) & "Geneva, Arial, Helvetica, sans-serif"& chr(34) & ">" & theContent & "</font></td></tr>")
to this:
Code:
Response.Write("<tr> <td width=""125"" rowspan=""2"" align=""center"" valign=""middle"" bgcolor=""#9999FF""> <font color=""#FFFFFF"" size=""2"" face=""Arial, Helvetica, sans-serif""><strong>by : " & rs("UserName") & "</strong></font><font size=""2"" face=""Arial, Helvetica, sans-serif""><br><br><font color=""#FFFFFF""><strong>Date:</strong> " & rs("Date") & "</font><br><font color=""#FFFFFF""><strong>Time:</strong> " & rs("Time") & "</font></font></td><td width=""559"" height=""39""><font color=""#CCCC33""><strong><em><u>Subject : " & theSubject & "</strong></font></u></em></td></tr><tr><td bgcolor=""#CCCCFF""><font size=""2"" face=""Geneva, Arial, Helvetica, sans-serif"">" & theContent & "</font></td></tr>")
OR, to make it even EASIER to debug, AND to make it process faster (this will take much less processor time):
Code:
%>
<tr>
    <td width="125" rowspan="2" align="center" valign="middle" bgcolor="#9999FF">
        <font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>by : <%=rs("UserName")%></strong></font><font size="2" face="Arial, Helvetica, sans-serif"><br><br>
        <font color="#FFFFFF"><strong>Date:</strong> <%=rs("Date")%></font><br>
<font color="#FFFFFF"><strong>Time:</strong> <%=rs("Time")%></font></font>
    </td>
    <td width="559" height="39">
        <font color="#CCCC33"><strong><em><u>Subject : <%=theSubject%></strong></font></u></em>
    </td>
</tr>
<tr>
    <td bgcolor="#CCCCFF">
        <font size="2" face="Geneva, Arial, Helvetica, sans-serif"><%=theContent%></font>
    </td>
</tr>
<%
Because you're not concatenating that gigantic string, it will be much easier faster.

Also of note, cawi17, the middle thing I said in my previous post about single quotes isn't a matter of being lazy, it's almost undoubtedly wrong and isn't returning the results you want (or will error out). Sure the ID of the parent isn't a string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top