Delphi从SQL数据库填充组合框项目 [英] Delphi filling combobox items from SQL database

查看:79
本文介绍了Delphi从SQL数据库填充组合框项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用SQL数据库中的数据填充组合框,但是它不起作用。我的查询与数据库有连接,查询的SQL属性字段是 select * from provider_table

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;

有人有想法吗?

推荐答案

这是您要寻找的吗?

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;

这篇关于Delphi从SQL数据库填充组合框项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆