IF Not Then response.write query help

S

Simon Gare

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
 
M

Mike

Simon Gare said:
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 :)
 
B

Bob Barrows [MVP]

Mike said:
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
 
S

Simon Gare

Thanks guys works perfectly.

Regards
Simon


Mike said:
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 :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top