Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: EOF Message


Message #1 by cyandle@c... on Fri, 17 Aug 2001 04:17:45
If you are using While Not rs.EOF how do you have an error message for 

records not found. Below is my code so that you can see what I am doing.



<% 

	'Dim local variables

	Dim sqlString, txtCategory, ColorSwitch, RowColor



	'Build sqlString

	txtCategory = Request.Form("txtcategory")

	sqlString = "SELECT Company, Address, City, State, Phone, Email, 

Website FROM members WHERE Category LIKE '%" & txtCategory & "%' AND 

MemberTypeID IN ('Primary', 'Associate', 'Non-Dues')"



	'Create recordset

	set rs = Server.CreateObject("ADODB.Recordset")

	rs.Open sqlString, "DSN=rvcc"

	

%>

        <div align="center">

          <table border="0" cellpadding="3" cellspacing="0">

            <tr bgcolor="CEE7FF">

              <td width="115"><b><font size="2" face="MS Sans Serif" 

color="#0000FF">Company</font></b></td>

              <td width="125"><b><font size="2" face="MS Sans Serif" 

color="#0000FF">Address</font></b></td>

              <td width="80"><b><font size="2" face="MS Sans Serif" 

color="#0000FF">City</font></b></td>

              <td width="35"><b><font size="2" face="MS Sans Serif" 

color="#0000FF">State</font></b></td>

              <td width="80"><b><font size="2" face="MS Sans Serif" 

color="#0000FF">Phone</font></b></td>

              <td width="160"><b><font size="2" face="MS Sans Serif" 

color="#0000FF">Email</font></b></td>

              <td width="160"><b><font size="2" face="MS Sans Serif" 

color="#0000FF">Website</font></b></td>

            </tr>

          </table>

        </div>

<%

	'Set Switch

	Switch = False



	'Set record switch to first record

	rs.MoveFirst



	'Loop through all records

	While NOT rs.EOF



	'Check row color

	IF ColorSwitch = False THEN

		RowColor = "FFFFFF"

	ELSEIF ColorSwitch = True THEN

		RowColor = "CEE7FF"

	END IF

	



%>

        <div align="center">

          <table border="0" cellpadding="3" cellspacing="0">

            <tr bgcolor = <%=RowColor%>>

              <td width="115"><font face="MS Sans Serif" color="#000000" 

size="1"><%=rs("Company") & " "%></font></td>

              <td width="125"><font face="MS Sans Serif" color="#000000" 

size="1"><%=rs("Address") & " "%></font></td>

              <td width="80"><font face="MS Sans Serif" color="#000000" 

size="1"><%=rs("City") & " "%></font></td>

              <td width="35"><font face="MS Sans Serif" color="#000000" 

size="1"><%=rs("State") & " "%></font></td>

              <td width="80"><font face="MS Sans Serif" color="#000000" 

size="1"><%=rs("Phone") & " "%></font></td>

              <td width="160"><font face="MS Sans Serif" color="#000000" 

size="1"><%=rs("Email") & " "%></font></td>

              <td width="160"><font face="MS Sans Serif" color="#000000" 

size="1"><%=rs("Website") & " "%></font></td>

            </tr>



<%

	'Next record

	rs.MoveNext



	IF ColorSwitch = False THEN

		ColorSwitch = True

	ELSE 

		ColorSwitch = False

	END IF



	wend

%>



</table>



        </div>



<%

	'Otherwise no record was found, so tell the user that

	Else

	  response.write "No members were found with the category of " & 

Category & "

	End If

	

	'Close Recordset

	rs.close

	Set rs=nothing

%>





Any help will be appreciated.  Thanks.
Message #2 by Kevn77@a... on Fri, 17 Aug 2001 02:44:22 EDT

In a message dated 8/16/2001 10:39:46 PM Pacific Daylight Time, 

cyandle@c... writes:





> 

> 

>     'Set record switch to first record

>     rs.MoveFirst

> 

>     'Loop through all records

>     While NOT rs.EOF

> 

>     'Check row color

>     IF ColorSwitch = False THEN

>         RowColor = "FFFFFF"

> 



just a guess but maybe the error is occuring when you do rs.MoveFirst it 

always starts at the beginining anyways..you could just drop that line and 

see if it works...





Message #3 by "Ken Schaefer" <ken@a...> on Fri, 17 Aug 2001 17:20:56 +1000
When you open a recordset you are *always* at the first record (if there are

recors), so you do not need to call .movefirst.



<%

objRS.Open



If objRS.EOF then

    Response.Write("no records")

Else

    While Not objRS.EOF

        ...' no need to call .movefirst here

    Wend

End If

%>



Cheers

Ken



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

----- Original Message -----

From: <cyandle@c...>

To: "ASP Databases" <asp_databases@p...>

Sent: Friday, August 17, 2001 4:17 AM

Subject: [asp_databases] EOF Message





: If you are using While Not rs.EOF how do you have an error message for

: records not found. Below is my code so that you can see what I am doing.

:

: <%

: 'Dim local variables

: Dim sqlString, txtCategory, ColorSwitch, RowColor

:

: 'Build sqlString

: txtCategory = Request.Form("txtcategory")

: sqlString = "SELECT Company, Address, City, State, Phone, Email,

: Website FROM members WHERE Category LIKE '%" & txtCategory & "%' AND

: MemberTypeID IN ('Primary', 'Associate', 'Non-Dues')"

:

: 'Create recordset

: set rs = Server.CreateObject("ADODB.Recordset")

: rs.Open sqlString, "DSN=rvcc"

:

: %>






  Return to Index