Solved

best way of writing ---

Posted on 2011-03-12
9
280 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:psantiangeli
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:
psantiangeli earned 250 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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:psantiangeli
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:psantiangeli
ID: 35131490
adilkhan:
Request("ID") is not from recordset but from http request...
0
 
LVL 23

Assisted Solution

by:Saqib Khan
Saqib Khan earned 250 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

816 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now