RhythmAddict112
Programmer
Hi all. Im using the GetRows method on my page mainly because I had to pull back a large amount of data and paging, either in a stored procedure or using ADO simply is not an option. So, I am using GetRows which works great, and fast. My issue is that if the query is run and there are no results, I need to gracefully display this. As of now, I just get this error:
Error Type:
ADODB.Recordset (0x800A0BCD)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/repstats.asp, line 147
Not cool. I know how you can easily handle BOF and EOF conditions (of course) using normal recordsets and ado however Im unsure how to accomplish simliar tasks using the GetRows method. Here is my code....(kind of long)
Thank you for your help in advance
Error Type:
ADODB.Recordset (0x800A0BCD)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/repstats.asp, line 147
Not cool. I know how you can easily handle BOF and EOF conditions (of course) using normal recordsets and ado however Im unsure how to accomplish simliar tasks using the GetRows method. Here is my code....(kind of long)
Thank you for your help in advance
Code:
' Declare our variables... always good practice!
Dim cnnGetRows ' ADO connection
Dim rstGetRows ' ADO recordset
Dim strDBPath ' Path to our Access DB (*.mdb) file
Dim arrDBData ' Array that we dump all the data into
' Temp vars to speed up looping over the array
Dim I, J
Dim iRecFirst, iRecLast
Dim iFieldFirst, iFieldLast
' MapPath to our mdb file's physical path.
'strDBPath = Server.MapPath("db_scratch.mdb")
' Create a Connection using OLE DB
Set cnnGetRows = Server.CreateObject("ADODB.Connection")
' This line is for the Access sample database:
'cnnGetRows.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
' We're actually using SQL Server so we use this line instead.
' Comment this line out and uncomment the Access one above to
' play with the script on your own server.
cnnGetRows.Open Application("OWR_ConnectionString")
' Execute a simple query using the connection object.
' Store the resulting recordset in our variable.
Set rstGetRows = cnnGetRows.Execute("SELECT distinct CREQNAME,"_
&" SUM(CASE WHEN (dSubmit between ('01-JAN-2004') and ('31-JAN-2004'))"_
&" OR (dApprRej between ('01-JAN-2004') and ('31-JAN-2004'))"_
&" AND (CREGION = 'NY')"_
&" AND (CCHANNEL = 2)"_
&"THEN 1 ELSE 0 END) Submitted,"_
&" SUM(CASE WHEN (iApprStatus=-1)"_
&" AND (iAppr2Status IS NULL OR iAppr2Status=-1)"_
&" AND (iBatch Is Null OR iBatch > 0)"_
&" AND (CREGION = 'NY')"_
&" AND (CCHANNEL = 2)"_
&"THEN 1 ELSE 0 END) Approved,"_
&" SUM(CASE WHEN (iApprStatus=0)"_
&" AND (iAppr2Status IS NULL OR iAppr2Status=0)"_
&" AND (iBatch Is Null OR iBatch > 0)"_
&" AND (CREGION = 'NY')"_
&" AND (CCHANNEL = 2)"_
&"THEN 1 ELSE 0 END) Rejected,"_
&" SUM(CASE WHEN (iApprStatus=0)"_
&" AND (iAppr2Status IS NULL OR iAppr2Status=-1)"_
&" AND (length(cAppr2ID)>0) AND (iAppr2Status Is Null)"_
&" AND (CREGION = 'NY')"_
&" AND (CCHANNEL = 2)"_
&"THEN 1 ELSE 0 END) Pending"_
&" FROM tbl_OpenWindowRequests"_
&" WHERE dSubmit between ('01-JAN-2004') and ('31-JAN-2004')"_
&" OR dApprRej between ('01-JAN-2004') and ('31-JAN-2004')"_
&" GROUP BY creqname")
' Now this is where it gets interesting... Normally we'd do
' a loop of some sort until we ran into the last record in
' in the recordset. This time we're going to get all the data
' in one fell swoop and dump it into an array so we can
' disconnect from the DB as quickly as possible.
arrDBData = rstGetRows.GetRows()
' Some notes about .GetRows:
' The Method actually takes up to 3 optional arguments:
' 1. Rows - A long integer indicating the number of rows to
' retreive from the data source and put into the
' array. Defaults to adGetRowsRest which
' retreives all the remaining rows.
' 2. Start - An ADO bookmark indicating which row we should
' begin from. It can also be one of the following
' three ADO constants: adBookmarkCurrent,
' adBookmarkFirst, adBookmarkLast. Defaults to
' the current row, so if you've been moving around
' the RS it'll pick up wherever you left off.
' 3. Fields - A single field name or number or an array of
' names or numbers indicating which fields to
' retreive and place into the array. Defaults to
' all the columns.
'
' So a example using all the attributes would look like this:
'
'arrDBData = rstGetRows.GetRows(2, adBookmarkCurrent, Array("id", "text_field"))
'
' Which would get 2 rows starting from the current record and
' only returning data from the the id and text_field fields.
'
' FYI: the above line uses an ADO constant from adovbs.inc
' which I haven't included in this script:
' Const adBookmarkCurrent = 0
' Close our recordset and connection and dispose of the objects.
' Notice that I'm able to do this before we even worry about
' displaying any of the data!
rstGetRows.Close
Set rstGetRows = Nothing
cnnGetRows.Close
Set cnnGetRows = Nothing
' ADO sets up the array so that the elements of the first
' dimension correspond to the DB fields and the elements of
' the second dimension correspond to the records. It might
' seem a little backward, but when you think about it, it
' makes sense because it's easy to modify the last dimension
' (to hold fewer or more records as needed), but modifying the
' first dimension is difficult so we use it to handle the
' fields which most likely wouldn't need to be modified.
' Here I get the upper and lower bounds of the field list
' and the records. This gives me some information about the
' data before I start and also allows me to not have to query
' the array for its bounds on each loop.
iRecFirst = LBound(arrDBData, 2)
iRecLast = UBound(arrDBData, 2)
iFieldFirst = LBound(arrDBData, 1)
iFieldLast = UBound(arrDBData, 1)
' Display a table of the data in the array.
' We loop through the array displaying the values.
%>
<table border="1">
<%
' Loop through the records (second dimension of the array)
For I = iRecFirst To iRecLast
' A table row for each record
Response.Write "<tr>" & vbCrLf
' Loop through the fields (first dimension of the array)
For J = iFieldFirst To iFieldLast
' A table cell for each field
Response.Write vbTab & "<td>" & arrDBData(J, I) & "</td>" & vbCrLf
Next ' J
Response.Write "</tr>" & vbCrLf
Next ' I
%>
</table>
<%
' That's all folks!
%>