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

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
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 @ Microsoft.com
What is Adovbs.inc and Why Do I Need It?
An Overview of ASP.NET

QUICK TIP:
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>")
	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
%>

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

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