Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

best way of writing ---

Posted on 2011-03-12
9
Medium Priority
?
290 Views
Last Modified: 2012-05-11
I have the following code on my asp vbscript page -

              <%if (descript.Fields.Item("JBATitle").Value) <> "" then%> <%=(descript.Fields.Item("JBATitle").Value)%> <%End if%>vacancy application

However it appears to be failing as I keep getting the following error --

File Name: /logn.asp
Line Number: 280
Description: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

Where line 280 is

<%if (descript.Fields.Item("JBATitle").Value) <> "" then%> <%=(descript.Fields.Item("JBATitle").Value)%> <%End if%>vacancy application


Is there a better way of writing the code?

Thank you
0
Comment
Question by:garethtnash
  • 4
  • 3
  • 2
9 Comments
 
LVL 11

Expert Comment

by:Paolo Santiangeli
ID: 35116921
hi,
seems your query does not return records....

0
 

Author Comment

by:garethtnash
ID: 35116936
Yes so IF statement  should not show anything in that case?
0
 
LVL 11

Accepted Solution

by:
Paolo Santiangeli earned 1000 total points
ID: 35116971
you have to check BOF and EOF:

if rs.eof and rs.bof then
 response.write("empty")
end if

have a look here:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_23394546.html
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 23

Expert Comment

by:Saqib Khan
ID: 35117498
That is correct EOF check is important.


After you do Rs.Open and whenever you try to access fields from table do this...


<%
  if NOT descript.Eof Then
%>

<%if (descript.Fields.Item("JBATitle").Value) <> "" then%> <%=(descript.Fields.Item("JBATitle").Value)%> <%End if%>vacancy application


<%


 Else

           Response.write "Nothing Found"

 End if

 

%>
0
 

Author Comment

by:garethtnash
ID: 35121682
Thanks, I have put that in place, however I'm still getting errors, is there anyway of the recordset having data when it is written, but not once it tries to write contents?

 is there a way of writing this instead or as well -

<%IF Request("ID") <> "" AND Not descript.EOF Or Not descript.BOF then Reponse.Redirect("xxx")%>

thanks
0
 
LVL 11

Expert Comment

by:Paolo Santiangeli
ID: 35123025
mmm EOF an BOF are both true when recordset is empty so youhave to check AND condition
0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 35125619
> <%IF Request("ID") <> "" AND Not descript.EOF Or Not descript.BOF then Reponse.Redirect("xxx")%>

NO, EOF or BOF check should be performed before you access ANY Data field.

why dont you do like this

if Not Rs.eof Then  
   varA = Rs("ID") ' some variable
end if


if varA = ""  Then
   ' code
end if
0
 
LVL 11

Expert Comment

by:Paolo Santiangeli
ID: 35131490
adilkhan:
Request("ID") is not from recordset but from http request...
0
 
LVL 23

Assisted Solution

by:Saqib Khan
Saqib Khan earned 1000 total points
ID: 35131520
yes..that you can do. however i would recommend like this..


IF Request("ID") <> "" Then

 If NOT Rs.Eof Then ' We have some Data

 Else  ' No Data Found

 End if


End if
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question