Delphi filling combobox items from SQL database
delphi, delphi-7
Solution
Is this what you are looking for?
procedure SelCombo(sql:ansiString;Q:TSQLQuery; var Combo:TComboBox);
var i: integer;
begin
Q.Close;
Q.SQL.Text:='';
Q.Open(sql);
Combo.Text:='';
while not Q.Eof do begin
Combo.Items.Add(Q.Fields.Fields[0].AsString);
Q.Next;
end;
Q.Close;
end;
Problem
I want to fill my combobox with data from a SQL database but it doesn't work. My query has a connection to the database, query SQL property field is `select * from provider_table` ``` Query1.SQL.Clear; Query1.SQL.Add('select name from provider_table where region_code = '+quotedstr('eng')'); Query1.Open; while NOT Query1.Eof do begin ComboBox1.Items.Add(Query1['name']); Query1.Next; end; ``` Does anyone have an idea? Thanks for the answers!