Help with the Find method

Discussion in 'MCSD' started by Kissi, Jan 3, 2004.

  1. Kissi

    Kissi Guest

    Hi,

    Could anyone please help me with the find method. I am trying to search for
    range of dates using the find method. Example: I want to find if
    1/02/2004-1/15/2004 exit in a database. The database has two tables;
    StartDate
    and EndDate.
    Thanks
     
    Kissi, Jan 3, 2004
    #1
    1. Advertisements

  2. The database has two tables;
    Do you really mean two columns?
     
    The Poster Formerly Known as Kline Sphere, Jan 3, 2004
    #2
    1. Advertisements

  3. Kissi

    Kissi Guest

    Sorry, the table has two colums.
    StartDate and EndDate.
     
    Kissi, Jan 4, 2004
    #3
  4. Sorry, the table has two colums.
    In which case it's best to 'filter' the records within the sql
    statement or stored procedure. Either way the underlying sql would
    look something like this: -

    Select * From YOUR_TABLE Where REQUIRED_DATE Between START_DATE_FIELD
    And END_DATE_FIELD

    If you need to 'filter' out any records after the resultset has been
    processed and returned, you should be able to set the Filter property
    of the recordset, i.e.

    Assuming ADO 2.x here (for ado dot net, you need to look at using a
    dataview).

    YourRecordset.filter = "REQUIRED_DATE > = START_DATE_FIELD and
    REQUIRED_DATE <= END_DATE_FIELD"

    BTW, not sure you should be looking at the Find method
     
    The Poster Formerly Known as Kline Sphere, Jan 4, 2004
    #4
  5. Kissi

    Jay Walters Guest

    So there are several ways to go about this.

    Find and FindRows are functions of a DataView which
    return an index and array of DataRowView objects
    respectively.

    Personally I use the DataTable.Select method to return an
    array of DataRow objects. Or.. if I'm binding, I create a
    new DataView and use the RowFilter Property to get my sub-
    set.

    Once you start getting in to DataRowView objects it can
    get a little hairy (if you're not very familiar with how
    these objects work in regards to binding).

    If you are looping through the filtered rows just to
    extract data or populate some fields, the array is
    probably lighter and faster ... if you want easy data
    binding you can use the dataview (especially since it has
    additional functions like sorting).

    (To ward off extreme geek comments, you could bind to an
    array of datarows if you really wanted (but it can be a
    pain). Use a "for" loop instead of a "for each" loop for
    maximum performance. Instead of creating a new dataview,
    you can use the DefaultView property of your DataTable,
    but I like to save this as an original copy of my result
    set (it's a consistancy thing for me) and use a new
    DataView for sub-sets.
     
    Jay Walters, Jan 5, 2004
    #5
  6. All good stuff Jay. The Select method should achieve the desired
    effect, but the Find method(s) won't help, hence why I commented on
    it.
     
    The Poster Formerly Known as Kline Sphere, Jan 5, 2004
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.