TherosEquipment
asked on
ADO question
Hello,
Here is my connection...
...
Data := ExtractFilePath(Applicatio n.ExeName) + '\sales.mdb';
try
ADOConnection2.ConnectionS tring :=
'Provider=Microsoft.Jet.OL EDB.4.0;' +
'Data Source=' + Data +';'+
'Persist Security Info=False';
...
From this I want to open a table called 'sales units' and populate Combobox3 with a list of the different text entries in the 'make' column.
From that, when a 'make' is selected, I want to load combobox4 with all the 'model' using a filterbyselection of combobox3.
I think I can figure it out from there, but it's been so long since I've had to do this, that I'm totally lost. I don't want to use any special db components, I just want to do this programmatically. "no predefined db connection settings.
I hope I'm being clear...
Thanks,
Gabe
Here is my connection...
...
Data := ExtractFilePath(Applicatio
try
ADOConnection2.ConnectionS
'Provider=Microsoft.Jet.OL
'Data Source=' + Data +';'+
'Persist Security Info=False';
...
From this I want to open a table called 'sales units' and populate Combobox3 with a list of the different text entries in the 'make' column.
From that, when a 'make' is selected, I want to load combobox4 with all the 'model' using a filterbyselection of combobox3.
I think I can figure it out from there, but it's been so long since I've had to do this, that I'm totally lost. I don't want to use any special db components, I just want to do this programmatically. "no predefined db connection settings.
I hope I'm being clear...
Thanks,
Gabe
ASKER
looks pretty strait forward, but the real problem I have is getting the data after I make the connection. see the last part of my question.
Thanks
Thanks
procedure TForm1.Button1Click(Sender : TObject);
begin
ADOQuery1.Active := False;
ADOQuery1.Connection:=ADOC onnection2 ;
ADOQuery1.SQL.Text := 'SELECT DISTINCT make FROM sales_units';
ADOQuery1.Active := True;
ComboBox3.Clear;
while not ADOQuery1.EOF do
ComboBox3.Items.Add(ADOQue ry1.FieldB yName('mak e').AsStri ng);
end;
begin
ADOQuery1.Active := False;
ADOQuery1.Connection:=ADOC
ADOQuery1.SQL.Text := 'SELECT DISTINCT make FROM sales_units';
ADOQuery1.Active := True;
ComboBox3.Clear;
while not ADOQuery1.EOF do
ComboBox3.Items.Add(ADOQue
end;
procedure TForm1.ComboBox3CloseUp(Se nder: TObject);
begin
ADOQuery2.Active := False;
ADOQuery2.Connection:=ADOC onnection2 ;
ADOQuery2.SQL.Text :=''
+ 'SELECT DISTINCT model FROM sales_units'
+ ' WHERE make = '
+ '''' + ComboBox3.Text + ''''
+ '';
ADOQuery2.Active := True;
ComboBox4.Clear;
while not ADOQuery2.EOF do
ComboBox4.Items.Add(ADOQue ry2.FieldB yName('mod el').AsStr ing);
end;
begin
ADOQuery2.Active := False;
ADOQuery2.Connection:=ADOC
ADOQuery2.SQL.Text :=''
+ 'SELECT DISTINCT model FROM sales_units'
+ ' WHERE make = '
+ '''' + ComboBox3.Text + ''''
+ '';
ADOQuery2.Active := True;
ComboBox4.Clear;
while not ADOQuery2.EOF do
ComboBox4.Items.Add(ADOQue
end;
ASKER
Ok,
no compile errors, but the program hangs and does not paint to the screen.
procedure TForm1.LoadComboBox3;
const
CONN_STR='Provider=Microso ft.Jet.OLE DB.4.0;Dat a Source=%s;Persist Security Info=False';
var
Data:string;
ADOTable:TADOTable;
begin
ADOTable:=TADOTable.Create (nil);
try
Data:=ExtractFilePath(Appl ication.Ex eName) + '\sales.mdb';
ADOConnection2.ConnectionS tring:=For mat(CONN_S TR, [Data]);
ADOConnection2.LoginPrompt :=False;
ADOTable.Connection:=ADOCo nnection2;
ADOTable.TableName:='sales _units';
ADOTable.Active:=True;
//do whatever you are going to do with your table here...
loadquery;
finally
ADOTable.Free
end
end;
procedure TForm1.LoadQuery;
begin
combobox3.Clear;
ADOQuery1.Active := False;
ADOQuery1.Connection:=ADOC onnection2 ;
ADOQuery1.SQL.Text := 'SELECT DISTINCT make FROM sales_units';
ADOQuery1.Active := True;
while not ADOQuery1.EOF do
ComboBox3.Items.Add(ADOQue ry1.FieldB yName('mak e').AsStri ng);
end;
I like this, because I can understand it, but Isn't there a way to do this just by using the ADOTable?
no compile errors, but the program hangs and does not paint to the screen.
procedure TForm1.LoadComboBox3;
const
CONN_STR='Provider=Microso
var
Data:string;
ADOTable:TADOTable;
begin
ADOTable:=TADOTable.Create
try
Data:=ExtractFilePath(Appl
ADOConnection2.ConnectionS
ADOConnection2.LoginPrompt
ADOTable.Connection:=ADOCo
ADOTable.TableName:='sales
ADOTable.Active:=True;
//do whatever you are going to do with your table here...
loadquery;
finally
ADOTable.Free
end
end;
procedure TForm1.LoadQuery;
begin
combobox3.Clear;
ADOQuery1.Active := False;
ADOQuery1.Connection:=ADOC
ADOQuery1.SQL.Text := 'SELECT DISTINCT make FROM sales_units';
ADOQuery1.Active := True;
while not ADOQuery1.EOF do
ComboBox3.Items.Add(ADOQue
end;
I like this, because I can understand it, but Isn't there a way to do this just by using the ADOTable?
> populate Combobox3 with a list of the different text entries in the 'make' column
'SELECT DISTINCT make FROM sales_units' does exactly above requirements
How to do it using ADOTable ?
'SELECT DISTINCT make FROM sales_units' does exactly above requirements
How to do it using ADOTable ?
ASKER
esoftbg,
Your solution is not producing the desired result. The Count is right, but all the combobox items are the same (the first "make" in the list).
for example...
ComboBox3 should contain...
Allen
Imer
Multiquip
but I'm getting...
Allen
Allen
Allen
Sorry :(
Your solution is not producing the desired result. The Count is right, but all the combobox items are the same (the first "make" in the list).
for example...
ComboBox3 should contain...
Allen
Imer
Multiquip
but I'm getting...
Allen
Allen
Allen
Sorry :(
Oh, excuse me, I forgot something important:
while not ADOQuery1.EOF do
begin
ComboBox3.Items.Add(ADOQue ry1.FieldB yName('mak e').AsStri ng);
ADOQuery1.Next; // it is very, very important !
end;
while not ADOQuery1.EOF do
begin
ComboBox3.Items.Add(ADOQue
ADOQuery1.Next; // it is very, very important !
end;
ASKER
esoftbg,
Your solution works and the question is yours.
Just one other thing...
Can you help with the sql query for this...
procedure TForm1.ComboBox4Change(Sen der: TObject);
begin
ADOQuery2.Active := False;
ADOQuery2.Connection:=ADOC onnection2 ;
ADOQuery2.SQL.Text :=''
+ 'SELECT price AND list FROM sales_units' // << This is not working
+ ' WHERE model = '
+ '''' + ComboBox4.Text + ''''
+ '';
ADOQuery2.Active := True;
label10.Caption := 'Price: $' + AdoQuery2.FieldByName('pri ce').AsStr ing;
label11.Caption := 'List Price: $' + AdoQuery2.FieldByName('lis t').AsStri ng;
end;
Your solution works and the question is yours.
Just one other thing...
Can you help with the sql query for this...
procedure TForm1.ComboBox4Change(Sen
begin
ADOQuery2.Active := False;
ADOQuery2.Connection:=ADOC
ADOQuery2.SQL.Text :=''
+ 'SELECT price AND list FROM sales_units' // << This is not working
+ ' WHERE model = '
+ '''' + ComboBox4.Text + ''''
+ '';
ADOQuery2.Active := True;
label10.Caption := 'Price: $' + AdoQuery2.FieldByName('pri
label11.Caption := 'List Price: $' + AdoQuery2.FieldByName('lis
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
const
CONN_STR='Provider=Microso
var
Data:string;
ADOTable:TADOTable;
begin
ADOTable:=TADOTable.Create
try
Data:=ExtractFilePath(Appl
ADOConnection2.ConnectionS
ADOConnection2.LoginPrompt
ADOTable.Connection:=ADOCo
ADOTable.TableName:='Sales
ADOTable.Active:=True;
//do whatever you are going to do with your table here...
finally
ADOTable.Free
end
end;
I created the ADOTable component dinamically, I don't know if you want that or to drop a component in the form...