EOF .NET equivalent?

Discussion in 'ASP .Net' started by D. Shane Fowlkes, Dec 3, 2003.

  1. 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
    *********************************
     
    D. Shane Fowlkes, Dec 3, 2003
    #1
    1. Advertising

  2. 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


    "D. Shane Fowlkes" <> wrote in message
    news:OF%...
    > 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
    > *********************************
    >
    >
    >
     
    S. Justin Gengo, Dec 3, 2003
    #2
    1. Advertising

  3. 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
    *********************************


    "S. Justin Gengo" <> wrote in message
    news:...
    > 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
    >
    >
    > "D. Shane Fowlkes" <> wrote in message
    > news:OF%...
    > > 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
    > > *********************************
    > >
    > >
    > >

    >
    >
     
    D. Shane Fowlkes, Dec 3, 2003
    #3
  4. 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.

    "D. Shane Fowlkes" <> wrote in message
    news:...
    > 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
    > *********************************
    >
    >
    > "S. Justin Gengo" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > > "D. Shane Fowlkes" <> wrote in message
    > > news:OF%...
    > > > 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
    > > > *********************************
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Kevin Spencer, Dec 3, 2003
    #4
  5. 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!
    **********************************************************************
    "D. Shane Fowlkes" <> wrote in message
    news:...
    > 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
    > *********************************
    >
    >
    > "S. Justin Gengo" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > > "D. Shane Fowlkes" <> wrote in message
    > > news:OF%...
    > > > 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
    > > > *********************************
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Cowboy \(Gregory A. Beamer\), Dec 3, 2003
    #5
  6. See answer farther down the thread!

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

    **********************************************************************
    Think Outside the Box!
    **********************************************************************
    "D. Shane Fowlkes" <> wrote in message
    news:OF%...
    > 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
    > *********************************
    >
    >
    >
     
    Cowboy \(Gregory A. Beamer\), Dec 3, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TmF0aGFuVg==?=

    RS.Eof to asp.net

    =?Utf-8?B?TmF0aGFuVg==?=, Sep 29, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    3,934
    Kevin Spencer
    Sep 29, 2004
  2. Kobu
    Replies:
    10
    Views:
    657
    Keith Thompson
    Mar 4, 2005
  3. glenn22
    Replies:
    1
    Views:
    3,061
    glenn22
    Apr 20, 2007
  4. SpreadTooThin

    ifstream eof not reporting eof?

    SpreadTooThin, Jun 13, 2007, in forum: C++
    Replies:
    10
    Views:
    713
    James Kanze
    Jun 15, 2007
  5. Jan Burse
    Replies:
    67
    Views:
    1,104
    Jan Burse
    Mar 14, 2012
Loading...

Share This Page