Click to See Complete Forum and Search --> : Checking to see if recordset is empty?


WoG
12-06-2004, 04:27 PM
How do you check to see if the query you loaded into a recordset -retuned nothing? I keep getting this error:
error '80020009' Exception occurred.

/admissions/reports/snap_rpt_TR.asp, line 61
With this code:
<%
If (result_TR_ADM(0)="") then
Response.Write ("No Data")
End if
%>


I know for sure that the result_TR_ADM recordset will not return any rows.


I want to check to see if a recordset is empty and have it bypass a whole load of code if so.


I've tried this:


<%
If (result_TR_ADM.EOF = True) then
Response.Write ("No Data")
End if
%>


And get this error:


Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'EOF'

/admissions/reports/includes/TR_adm.inc, line 2

Which really confuses me... I have adovbs.asp included...


Anyone?
Edit/Delete Message

candelbc
12-06-2004, 04:35 PM
Is the result_TR_ADM object declared somewhere as a ADODB.Recordset?

Because the "If result_TR_ADM.EOF = True" statement should work.

-Brad

WoG
12-06-2004, 04:42 PM
Here's the code:

<%
Set cn = Server.CreateObject("ADODB.Connection")
cn.ConnectionString = "Driver=SQL Server;Server=details..."
cn.Open
Set result_TR_ADM = Server.CreateObject("ADODB.RecordSet")

sql_tr_adm = "SELECT * FROM rpt_temp_snap WHERE (ClassName = 'Transfer') AND (StatusCluster = 'Admit' OR StatusCluster = 'Enrolled')"
%>
...
<%
result_TR_ADM = cn.execute(sql_tr_adm)
%>

Then I try and check to see if the result_TR_ADM is empty.
Thanks,
WoG

candelbc
12-06-2004, 04:57 PM
<%
Set cn = Server.CreateObject("ADODB.Connection")
cn.ConnectionString = "Driver=SQL Server;Server=details..."
cn.Open
Set result_TR_ADM = Server.CreateObject("ADODB.RecordSet")

sql_tr_adm = "SELECT * FROM rpt_temp_snap WHERE (ClassName = 'Transfer') AND (StatusCluster = 'Admit' OR StatusCluster = 'Enrolled')"
%>

<%
result_TR_ADM.Open sql_tr_adm,,,adCmdTable

If result_TR_ADM.EOF = True THen
Response.Write "No records
Else
'Do stuff with records
End If


That help any?



Originally posted by WoG
Here's the code:

<%
Set cn = Server.CreateObject("ADODB.Connection")
cn.ConnectionString = "Driver=SQL Server;Server=details..."
cn.Open
Set result_TR_ADM = Server.CreateObject("ADODB.RecordSet")

sql_tr_adm = "SELECT * FROM rpt_temp_snap WHERE (ClassName = 'Transfer') AND (StatusCluster = 'Admit' OR StatusCluster = 'Enrolled')"
%>
...
<%
result_TR_ADM = cn.execute(sql_tr_adm)
%>

Then I try and check to see if the result_TR_ADM is empty.
Thanks,
WoG

WoG
12-06-2004, 05:00 PM
Yeah...I was trying to open the RS twice...kinda. It's better now. Thanks for the help!

candelbc
12-06-2004, 05:04 PM
Any time...