EOF .NET equivalent?

  • Thread starter Thread starter D. Shane Fowlkes
  • Start date Start date
D

D. Shane Fowlkes

When using classic ASP, I would use something like what's below to show HTML
if the recordset was empty.

<% If RS.EOF And RS.BOF Then %>
<p>There are no records to display.</p>
<% End If %>

Now...as I'm learning ASP.NET, I'll use something like what's below to loop
thru a recordset.

<%
While MyData.Read()
Response.Write...stuff.....
End While
%>

But as simple as it may seem, I cannot find any references in my books or
online how to "detect" if the recordset is empty. I'm basing my SELECT
statement off of a search form so if the user types something that's not
useful like "tuvwxyz", the query will most likely return nothing. Any
pointers?

Thanks

--



*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************
 
Shane,

If there are no records While MyData.Read will never begin the loop.

It's just skipped over automatically because .Read never fires since there
are no records.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Yes, I know. That's my point. How would I display a message indicating
there are no records when there are no records? For example...

<% If Not RS.EOF Or Not RS.BOF Then %>
Go thru my loop and display records.......
<% Else %>
<p> Sorry, there are no matching your request at this time. </p>
<% End If%>

Thanks

--


*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************
 
if objDR.Read() then
Do
...
Loop While objDR.Read()
Else
...
End If

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
There are a couple of ways. Using your methodology, you can do the
following:

<%
Dim blnRecords As Boolean = false

While MyData.Read()
'Set boolean
blnRecords = true
Response.Write...stuff.....
End While

If blnRecords = False then
Response.Write("No records dood!")
End If
%>

In general, I would learn to write from codeBehind, rather than embed code.
While it was necessary in ASP, it is bad form, overall, in ASP.NET (changes
a bit in ASP.NET 2.0 - Whidbey, but that is another story).

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
See answer farther down the thread!

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Back
Top