在Delphi中,放入一个combobox1或一个edit1,并且有一个以建好的供货商信息表,那么在程序中如何写代码来判断该供应商编号不存在呀!

解决方案 »

  1.   

    combobox1.clear;
    with AdoQuery1 do
    begin
      close;
      sql.clear;
      sql.add('select distinct 供应商编号 from 供货商信息表');
      Open;
      while not eof do
        comboBox1.Items.add(FieldByName('供应商编号').asString);
    end;
    with adoQuery1 do
    begin
      close;
      sql.clear;
      sql.text:= 'select * from 供货商信息表 where 供应商编号='''+ combobox1.text + '''';
      Open;
      if eof then
        //没有此编号
      else
        ;//有。
    end;
      

  2.   

    //改一下
    with adoQuery1 do
    begin
      close;
      sql.clear;
      sql.text:= 'select * from 供货商信息表 where 供应商编号='''+ combobox1.text + '''';
      Open;
      if recordCount =0 then
        //没有此编号
      else
        ;//有。
    end;