Need help with a query

If you are a Delphi developer and have any questions about using our products from Delphi here is the place to post them.
Post Reply
Goose
Posts: 3
Joined: Mon Mar 21 2005

Need help with a query

Post by Goose »

Hi,
I have not programmed in a few years and forgot more than I remembered.
I am trying to make a simple program that has a GUI to access 2 tables.
My 2 tables are:
MasterEntity.db (Contains a list of stores, field name "Entity")
DetailEntity.db (Contains stores and store numbers, fields are "Entity" and "Number".

I have set up 2 table and dataset comps on the form and have no problem accessing my tables in general. I also added a query comp with a dataset for what I need below.

I have dropped 2 DBLookupComboBox's on the form. The first combobox is populated from my master table and lists all the store names. The second combobox is linked to the query I am having trouble with.

What I want to do is select a store from the first box, then OnExit of that box, have the query populate the store numbers from the detail table that match up with the store I selected in the first box.

Mt code looks like this:
procedure TForm1.DBLookupComboBox1Exit(Sender: TObject);
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add ('Select * ');
Query1.SQL.Add ('FROM DetailEntity.db');
Query1.SQL.Add ('WHERE Entity = ' + DBLookupComboBox1.Text);
Query1.Open;
end;


When I run it, I can select the store, but when I exit the box, the query run and it says the store name I selected does not exist. What am I doing wrong here?
Goose
Posts: 3
Joined: Mon Mar 21 2005

Post by Goose »

I didnt have the proper syntax, left out ticks, should have had last line like this:

Query1.SQL.Add ('WHERE Entity = ''' + DBLookupComboBox4.Text + '''');
Post Reply