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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filling a combo box with info from a database 3

Status
Not open for further replies.

patlim88

Programmer
May 14, 2002
22
US
I'm trying to fill a TDBCombo box with information from a database. I have the appropriate SQL query and update in place but when I run the app I get a EDatabaseError with message 'CallBackQ: Field 'BackIndex' not found'. The code below is in place on form create and is the place that is highlighted after I hit OK from the error message. Does anyone know what's going on?

Thanks.

Pat

procedure TForcedCall.FormCreate(Sender: TObject);
begin

CallBackQ.Close;
CallBackQ.Prepare;
CallBackQ.OpenDatabase;
if(length(CallBackQ.FieldByName('BACKINDEX').AsString)=1) then
CallBackCB.Text:='0'+CallBackQ.FieldByName('BACKINDEX').AsString
else
CallBackCB.Text:=CallBackQ.FieldByName('BACKINDEX').AsString;
 
hi,

As far as I can see at the moment, the line with

CallBackQ.OpenDatabase;

is wrong. It wil open the database connected to the used dataset. This is not what you want. You want to execute the query in CallBackQ. So the Line should read

CallBackQ.Open;

In this case the query will be executed and thei will be a field with the name BackIndex.

Steph [bigglasses]
 
Thanks that worked!

The field 'Backindex' has numerous items. At the moment it is only showing 1 record in the combo box when there are 5 records. Would you know how to show multiple records in the combo box?

Thanks.

Patrick
 
As soon as you open a query, the dataset 'pointer' is set to the first record which is the one you can see. You need a loop for each record in the dataset. I'll use a simplified eg.

combo.items.clear;
qry.open
while not qry.eof do
begin
combo.items.add(qry.fieldbyname('ssss').asstring);
qry.next;
end;

Is this what you want ?

lou
 
That worked perfectly!!! Thanks!

When I select an item in the combo box it doesn't show in the box after I select it.

Would you know how to show the selected item?

Thanks.

Patrick
 
hi Patrick. Are you saying it doesn't show in the box part of the Combo after selection? I'm not sure why, are you doing anything extra in one the the Combo's events? Are you using the normal combo or the DBCombo still?

 
The DbCombobox is different from the combobox, that it will show as the selected item, the data in the table or query. If there is no data in the corresponding field it will show up empty.
We use the DbCombobox to ensure that only certain data is entered in the database.

Regards Steven van Els
SAvanEls@cq-link.sr
 
I was using the DBCombo but now that I have changed it to a normal combo, it works. Based on what Steven wrote ... I'll need to use the DBCombo because I cannot let the user change what is being selected in the combo box.

Any ideas on how to make the selection show up in the combo box using a DB Combo?

Thanks guys!

Patrick
 
You could change the 'Style' property to 'csDropDownList' rather than 'csDropDown'.

lou
 
I kept the normal combo box and changed the style property to csDropDownList ... it's working just as i wanted!

Thanks!!!

Patrick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top