ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
The Top 10 ASP Links @
What is and Why Do I Need It?
An Overview of ASP.NET

Update Your ADO Components
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

Use RecordSet.Filter

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>")
	‘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>")
	Set oRS = Nothing

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers