Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple ADOQuery In Single DBGRID ..not possible?

Status
Not open for further replies.

Tony1l

Programmer
Dec 21, 2002
30
US
I'm trying to pull off running a query multiple times and populating a single DBGRID. I would like the results to append to the bottom of the DBGRID but have landed flat on my face.
I'm assigning the variable 'item' with a differing value and looping back through a the query again but will no luck. There's probably some basic rule that I'm violating and if so please suggest an alternative.
This is pulling a number from a TstringList sending it through a query then pulling another number (repeat until End of stinglist count)


Here's the code sample:

var
stringlist:Tstringlist;
i:integer;
s,Item,sql:string;

Begin
Stringlist:=Tstringlist.create;
Stringlist.loadfromfile('...
...
...
for i:=0 to Stringlist.count-1 do
Begin
s:=stringlist;
item:=copy(S,1,6);
adoquery1.close;
adoquery1.sql.clear;
sql:='select description from items where itemnumber='+quotedstr(item)+'';
adoquery1.sql.add(SQL);
adoquery1.open;
End;
Stringlist.free

//I can populate the DBGRID with a single SQL query entered directly from the ADOQUERY1 property so my connections are good but my logic is probably twisted somewhere.
I've stepped traced through the code and it's properly getting a different value on each loop but ending with an empty DBGRID.
Is there an easier way?






 
How about using a single query, but modifying the SQL using the UNION command to append the queries together?

ie.

Query1
Code:
SELECT Field1, Field2 FROM Table1

Query2
Code:
SELECT Field1, Field2 FROM Table2 WHERE Field1="XXX"

becomes:

Query1
Code:
SELECT Field1, Field 2 FROM Table1
UNION ALL
SELECT Field1, Field2 FROM Table2 WHERE Field1="XXX"

You can programmatically create the SQL of course if that's necessary.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top