IF Not Then response.write query help

Discussion in 'ASP General' started by Simon Gare, Jan 9, 2007.

  1. Simon Gare

    Simon Gare Guest

    Hi All,

    having a problem with the error "Either BOF or EOF is True, or the current
    record has been deleted. " found a workaround that allows the non existent
    data to be bypassed and insert a 0 value into the textfield and inserted
    into the table, however if the record does exist it still shows the 0 value?
    I want it to Response.Write the recordset value entry.

    At present
    <input name="BroughtForward" type="hidden" id="BroughtForward" value="<% If
    Not rsDriverPayments.EOF OR rsDriverPayments.BOF Then Response.Write "0" END
    If %> ">

    I would like it to work like

    <input name="BroughtForward" type="hidden" id="BroughtForward" value="<% If
    Not rsDriverPayments.EOF OR rsDriverPayments.BOF Then Response.Write "0"
    ELSE Response.Write rsDriverPayments.Fields.Item("BroughtForward").Value END
    If %> ">


    Simon Gare
    The Gare Group Limited

    website: www.thegaregroup.co.uk
    website: www.privatehiresolutions.co.uk
     
    Simon Gare, Jan 9, 2007
    #1
    1. Advertising

  2. Simon Gare

    Mike Guest

    "Simon Gare" <> wrote in message
    news:...
    > Hi All,
    >
    > having a problem with the error "Either BOF or EOF is True, or the current
    > record has been deleted. " found a workaround that allows the non existent
    > data to be bypassed and insert a 0 value into the textfield and inserted
    > into the table, however if the record does exist it still shows the 0
    > value?
    > I want it to Response.Write the recordset value entry.
    >
    > At present
    > <input name="BroughtForward" type="hidden" id="BroughtForward" value="<%
    > If
    > Not rsDriverPayments.EOF OR rsDriverPayments.BOF Then Response.Write "0"
    > END
    > If %> ">
    >
    > I would like it to work like
    >
    > <input name="BroughtForward" type="hidden" id="BroughtForward" value="<%
    > If
    > Not rsDriverPayments.EOF OR rsDriverPayments.BOF Then Response.Write "0"
    > ELSE Response.Write rsDriverPayments.Fields.Item("BroughtForward").Value
    > END
    > If %> ">
    >


    You are telling it to show 0 if your recordset is NOT End Of File, and to
    write a non-existent record if it is:

    If Not rsDriverPayments.EOF OR rsDriverPayments.BOF Then
    'This line detects that there are records available
    Response.Write "0"
    ELSE 'if rsDriverPayments is EOF or rsDriverPayments is BOF
    Response.Write rsDriverPayments.Fields.Item("BroughtForward").Value
    ' if it's EOF or BOF, there are no records to write
    END If


    You should be doing it the other way round:

    If Not rsDriverPayments.EOF Then
    Response.Write rsDriverPayments("BroughtForward")
    Else
    Response.Write "0"
    End IF

    Incidentally, the full test for a populated recordset should be:

    If NOT rs.EOF Or NOT rs.BOF

    In other words, there should be a NOT in front of both EOF and BOF. Also, I
    seem to recall from a previous post by Bob Barrows that the test for BOF is
    unnecessary when using a default forward-only cursor, so only testing for
    EOF is needed in 99% of cases. I'm sure he will correct me if I got that
    wrong :)

    --
    Mike Brind
     
    Mike, Jan 9, 2007
    #2
    1. Advertising

  3. Mike wrote:
    >
    > Incidentally, the full test for a populated recordset should be:
    >
    > If NOT rs.EOF Or NOT rs.BOF
    >
    > In other words, there should be a NOT in front of both EOF and BOF. Also,
    > I seem to recall from a previous post by Bob Barrows that the
    > test for BOF is unnecessary when using a default forward-only cursor,
    > so only testing for EOF is needed in 99% of cases. I'm sure he will
    > correct me if I got that wrong :)


    Well, since you called ...
    If a recordset contains any records at all, it will always be "ponting" at
    the first record when the recordset is opened. So only one of the properties
    (EOF, BOF) needs to be tested immediately after opening the recordset. It
    really does not matter which one you test (BOF or EOF), but I typically
    choose EOF because ... well, .. for absolutely no good reason. It just
    sounds better to me.

    BOF can only be true if you make an attempt to MoveFirst or MovePrevious,
    so, as you say, with a forward-only cursor, BOF will probably never be true,
    unless you start playing with the Cachesize property. If more than one
    record is in the cache, backward navigation will be possible even with a
    forward-only cursor. The "forward-only" relates to how the records are
    retrieved from the server-side cursor.

    Once navigation has been done through a recordset, or records have been
    deleted from it, then both BOF and EOF need to be tested to determine if it
    is empty.

    For the OP: you should study the terms I've mentioned in the ADO
    documentation which is available here:
    http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoapireference.asp

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Jan 9, 2007
    #3
  4. Simon Gare

    Simon Gare Guest

    Thanks guys works perfectly.

    Regards
    Simon


    "Mike" <> wrote in message
    news:...
    >
    > "Simon Gare" <> wrote in message
    > news:...
    > > Hi All,
    > >
    > > having a problem with the error "Either BOF or EOF is True, or the

    current
    > > record has been deleted. " found a workaround that allows the non

    existent
    > > data to be bypassed and insert a 0 value into the textfield and inserted
    > > into the table, however if the record does exist it still shows the 0
    > > value?
    > > I want it to Response.Write the recordset value entry.
    > >
    > > At present
    > > <input name="BroughtForward" type="hidden" id="BroughtForward" value="<%
    > > If
    > > Not rsDriverPayments.EOF OR rsDriverPayments.BOF Then Response.Write "0"
    > > END
    > > If %> ">
    > >
    > > I would like it to work like
    > >
    > > <input name="BroughtForward" type="hidden" id="BroughtForward" value="<%
    > > If
    > > Not rsDriverPayments.EOF OR rsDriverPayments.BOF Then Response.Write "0"
    > > ELSE Response.Write rsDriverPayments.Fields.Item("BroughtForward").Value
    > > END
    > > If %> ">
    > >

    >
    > You are telling it to show 0 if your recordset is NOT End Of File, and to
    > write a non-existent record if it is:
    >
    > If Not rsDriverPayments.EOF OR rsDriverPayments.BOF Then
    > 'This line detects that there are records available
    > Response.Write "0"
    > ELSE 'if rsDriverPayments is EOF or rsDriverPayments is BOF
    > Response.Write rsDriverPayments.Fields.Item("BroughtForward").Value
    > ' if it's EOF or BOF, there are no records to write
    > END If
    >
    >
    > You should be doing it the other way round:
    >
    > If Not rsDriverPayments.EOF Then
    > Response.Write rsDriverPayments("BroughtForward")
    > Else
    > Response.Write "0"
    > End IF
    >
    > Incidentally, the full test for a populated recordset should be:
    >
    > If NOT rs.EOF Or NOT rs.BOF
    >
    > In other words, there should be a NOT in front of both EOF and BOF. Also,

    I
    > seem to recall from a previous post by Bob Barrows that the test for BOF

    is
    > unnecessary when using a default forward-only cursor, so only testing for
    > EOF is needed in 99% of cases. I'm sure he will correct me if I got that
    > wrong :)
    >
    > --
    > Mike Brind
    >
    >
     
    Simon Gare, Jan 9, 2007
    #4
    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. Charles A. Lackman
    Replies:
    2
    Views:
    8,092
    Charles A. Lackman
    Jan 11, 2006
  2. Matthew Wieder

    Response.Write and Response.Redirect

    Matthew Wieder, Jul 17, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    754
    Kevin Spencer
    Jul 17, 2003
  3. Sehboo
    Replies:
    3
    Views:
    8,932
    Sehboo
    Dec 10, 2003
  4. Replies:
    0
    Views:
    337
  5. Replies:
    15
    Views:
    247
Loading...

Share This Page