回 帖 发 新 帖 刷新版面

主题:用DBCombobox 选表中某一字段的不重复记录,为什么总是出错

procedure Tjlck.DBComboBox1DropDown(Sender: TObject);
begin
//  原理:利用xhpzQuery获取不重复数据记录
//  将数据一条一条传入到Combobox中

     with xhpzquery do
    begin
      if xhpzquery.active then
      xhpzquery.Close;
      xhpzquery.SQL.Clear;
      xhpzquery.SQL.Add('select distinct 型号配置 * from kczb');
      xhpzquery.ExecSQL ;
    end;
      if xhpzquery.recordcount>0 then
        begin
          showmessage(' xhpzquery.recordcount>0');
          DBComboBox1.Items.clear;
          xhpzquery.open;
          DBComboBox1.Items.clear;
          xhpzquery.First;
          while not xhpzquery.Eof do
          begin
           DBComboBox1.Items.Add(xhpzquery.FieldByName('型号配置').AsString);
           xhpzquery.Next;
          end;

       end;
end;

回复列表 (共3个回复)

沙发

procedure Tjlck.DBComboBox1DropDown(Sender: TObject);
begin
  with xhpzquery do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select distinct 型号配置 * from kczb');
      open;
      First;
    end;
    if xhpzquery.recordcount>0 then
      begin
        DBComboBox1.Items.clear;       
        while not xhpzquery.Eof do
          begin
           DBComboBox1.Items.Add(xhpzquery.FieldByName('型号配置').AsString);
           xhpzquery.Next;
          end;

       end;
end;

板凳


还是不行,一选dbcombobox提示: project project1.exe raised exception class EDBEngineError with message'invalid use of keyword.Token From Line Number :1.Process STopped. use step or run to continue

3 楼

SQL.Add('select distinct 型号配置 * from kczb');
把*去掉!这种错误用断点跟踪一下就马上知道了。

我来回复

您尚未登录,请登录后再回复。点此登录或注册