Database
  Home arrow Database arrow Page 3 - Manipulating ADO Recordsets
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

Manipulating ADO Recordsets
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 6
    2006-06-21

    Table of Contents:
  • Manipulating ADO Recordsets
  • Sorting the recordset
  • Filtering the Recordset
  • Using the Filter property of the recordset
  • Recordset's Find() method

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Manipulating ADO Recordsets - Filtering the Recordset
    (Page 3 of 5 )

    The worst crime you can commit is to get all the server data to the client application. In order to minimize your call on resources it is always recommended that you get just what you need. That is, you should try to Filter your data; try to focus. The filter property does just that. For example, in our Employees table there are people coming from five different cities, and there are 11 people. This means there is more than one person coming from one or two of the cities. Let's say you just want to find those coming from "London." In this case you will filter so that, those not coming from "London" will be removed from the list.

    Using the Where Clause in the query

    This tutorial gives you only the basics for using the filter. There are other values such as the FilterGroupEnum enumeration that can be provided for the filter property. These will not be considered here.

    In ADO you can do filtering two ways. You can do filtering using the "Where" clause in your original recordset retrieval process. This will bring in what you want, ready to use. Create a form and drop in controls as shown; the code that follows will be based on these controls.

    The Combo0's click event will fill the comb with a sorted list of Cities, with no city being repeated. This is read-only and fills up the Combo Box fast. The "Distinct" keyword removes the duplicates from the list (London and Seattle would appear only once) and the Order By sorts the cities in the default ascending order. To initiate this event, double click on the Combo Box's label. Then click on the Combo Box's down arrow to reveal the cities as shown.

    Now pick a city and click on the button at the bottom. This retrieves the recordset from a parametric query, which is highlighted, and uses the Combo Box's text as the argument. The rest of the code is just retrieving the recordset and stuffing it into a ListBox. Additionally a textbox (unbounded; see the design view) has been added to show the name of the (filtered) city that is chosen.

    Option Compare Database
    Private cn As ADODB.Connection
    Private rst As ADODB.Recordset
    Private Sub Combo0_DblClick(Cancel As Integer)
    Dim str As String
    str = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=C:Documents and SettingsJayMy Documents
    Retrieve.mdb;" & _ "Persist Security Info=False" Dim strSql As String 'strSql = "Employees" Set cn = New ADODB.Connection cn.Open str Set rst = New ADODB.Recordset rst.CursorLocation = adUseClient strSql = "Select distinct City from Employees
    order by City"
    rst.Open strSql, cn, adOpenReadOnly MsgBox (rst.Fields.Count) Set Me.Recordset = rst Dim strg strg = "" While Not rst.EOF strg = strg & rst.Fields.Item(0).Value & ";" rst.MoveNext Wend Me.Combo0.RowSource = strg 'rst.Close 'cn.Close End Sub Private Sub Command2_Click() Combo0.SetFocus cmbtxt = Combo0.Text 'MsgBox (Combo0.Text) Me.List5.RowSource = "" Text7.SetFocus Text7.Text = cmbtxt Dim str As String str = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:Documents and SettingsJayMy Documents
    Retrieve.mdb;" & _ "Persist Security Info=False" Dim strSql As String 'strSql = "Employees" Set cn = New ADODB.Connection cn.Open str Set rst = New ADODB.Recordset rst.CursorLocation = adUseClient
    strSql =
    "Select LastName, FirstName, HireDate, " & _
    "City from Employees where City = " & "'" & cmbtxt & "'"
    MsgBox (strSql) rst.Open strSql, cn, adOpenDynamic Set Me.Recordset = rst strinfo = "" While Not rst.EOF strinfo = strinfo & rst.Fields.Item(0).Value & " : " & _
    rst.Fields.Item(1).Value & " : " & _ "rst.Fields.Item(2).Value & " : " & rst.Fields.Item(3).
    Value & ";" rst.MoveNext MsgBox (strinfo) Wend Me.List5.RowSource = strinfo rst.Close cn.Close End Sub

    The result of this code is shown in the next picture where the value "Seattle" was picked in the Combo Box, and the Command Button "Employee Info by City" was clicked.

    DATABASE ARTICLES

    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005
    - Manipulating ADO Recordsets




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway