Reuse a single Recordset by using the filter method.
It is much more efficient and so much easier to maintain, than opening up multiple recordsets, using multiple SQL selects.
If you know you are going to need a large subset of data, just get everything once and then filter it as you need it.
Example Below:
<%
Const adFilterNone = 0
Const adFilterPendingRecords = 1
Const adFilterAffectedRecords = 2
Const adFilterFetchedRecords = 3
Const adFilterConflictingRecords = 5
Dim oRS, strSQL, strConn
Set oRS = Server.CreateObject("ADODB.RecordSet")
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
&"Data Source=C:\Data\FPNWIND.mdb;"
strSQL = "SELECT * FROM Products"
oRS.Open strSQL, strConn, 3, 3
oRS.Filter = "UnitPrice < $20.00"
'Recordset contains
'Only Records Where the Unit Price is Less than $20
Do While Not oRS.EOF
Response.Write(oRS("CategoryID") & "<BR>")
oRS.MoveNext
Loop
‘Remove Filter
oRS.Filter = adFilterNone
'RecordSet Now Contains All Field Data again
oRS.Filter = "SupplierID = 10"
'Recordset contains
'Only Records Where the Supplier ID is 10
Do While Not oRS.EOF
Response.Write(oRS("CategoryID") & "<BR>")
oRS.MoveNext
Loop
oRS.Close
Set oRS = Nothing
%>
If you have a tip you would like to submit, please send it to:
webmaster@asp101.com.