Re: Sub Selects?

From: Mike Walsh (techs.msllib.com_at_verizon.net)
Date: 03/23/04

  • Next message: Dennis: "Re: XML file to ADO table"
    Date: Tue, 23 Mar 2004 08:24:32 -0500
    
    

    "Michael Koziarski" <michael@koziarski.com> wrote in message
    news:405ffff5@newsgroups.borland.com...
    > Hey guys,
    >
    > I'm currently writing my first Delphi application, it's using ADO to
    connect
    > to a Jet database.
    >
    > I have to pull out data from one table, based on items selected in the UI.
    > Now, what I'd like to do is write something like:
    >
    > SELECT name, dob, income FROM Customer WHERE CustomerID IN
    > (1,2,3,4,5,6,9,294)
    >
    > But I can't figure out how to do this with Parameters or Filters. Is
    there
    > some nice Delphi DB technique to do this, or should I just build up the
    SQL
    > and escape things manually.
    >
    > Alternatively, should I just pull back all the records and skip the ones
    not
    > relevant (potentially very slow).
    >
    >
    > Cheers
    >
    > Koz
    >
    Koz, (What's wrong with Mike?)

    I don't believe you can do this with parameters. Due to the way that the ado
    stuff sets itself up, its not allowed.

    You can easily do this with parameters. One way would be to add a tlist to
    your form. A tlist is really a list of pointers, but as pointers and
    integers are both the same size, you can use the list to hold the selected
    customers ids using type casting. During the OnFilterRecords event, you
    simply check to see if the records id is in the list...

    For these examples, lets assume that you have a list called SelectedIds
    This assumes that you want to automatically adjust the list when a record is
    selected. To add an item to the list. I'd declare a pointer called Id, then

    Id := pointer (adoquery1.fieldbyname ('CustomerId').asinteger);
    if (SelectedIds.indexof (Id)) < 0) then
      SelectedIds.add (Id);

    The OnFilterRecords event would simply ise the same logic for determining if
    the id is in the list and set the Accept value accordingly.

    That being said, I'd recommend against using the filtering method. I'm not
    sure which version of Delphi you're using, but with D5, I know that there
    are issues with the ADO components and filters. Also, if you have 1000s of
    records, and only want to see a single one the filtering method brings all
    of them to your program forcing you to look at and reject all but the one.
    IMHO, the best way is to redefine your query each time and do a reselect.

    Mike Walsh


  • Next message: Dennis: "Re: XML file to ADO table"

    Relevant Pages

    • Re: Delphi 8 and ado.net
      ... > different to using say ADO in Delphi? ... The Delphi ADO implementation is basically a wrapper around the Recordset ... have cursors into the database, there are no cursors in ADO.NET. ...
      (borland.public.delphi.non-technical)
    • Re: recursive sp, fmtonly, ado,
      ... This was the first thing I've checked, because I suspect Delphi. ... It's in somewhere inside ADO or OLEDB. ... >> create procedure fmttest ...
      (microsoft.public.sqlserver.programming)
    • Re: Field position in a record, how to change?
      ... If you know how to move fields with DAO you can use Ole to access the ... I have found how to obtain the (ADO) FieldDefs for the ... (I am searching documentations for this option but your answer might ... I may just have found the answer in my saved Delphi 5 help files ...
      (borland.public.delphi.database.ado)
    • Re: BDE alternatives?
      ... Remember that Hannes is a developer for NexusDB, ... Anyway, I think every Delphi DB solution will, after the next Delphi.NET ... In either case, in practice, you put down an ADO connection ...
      (borland.public.delphi.non-technical)
    • Re: slow ADO refresh, ending in error message
      ... It seems to me that if the feature works fine with some implementations ... with Delphi 7) and poorer with other implementations (the Delphi 7 ... >>Is ADO only for small databases then? ... > You can use any size database with ADO but if you want good performance you ...
      (borland.public.delphi.database.ado)