Re: Sub Selects?
From: Mike Walsh (techs.msllib.com_at_verizon.net)
Date: 03/23/04
- Previous message: Viatcheslav V. Vassiliev: "Re: problem in adoquery.sql.text"
- In reply to: Michael Koziarski: "Sub Selects?"
- Next in thread: Júlio Silva: "Re: Sub Selects?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: Viatcheslav V. Vassiliev: "Re: problem in adoquery.sql.text"
- In reply to: Michael Koziarski: "Sub Selects?"
- Next in thread: Júlio Silva: "Re: Sub Selects?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|