程序用到ADO控件,ADOQUERY1连接到ORICAL,ADOQUERY2连接到SQLSERVER2000,在ORICAL和SQLSERVER下分别有两张表CUSTOM和CISCUSTOMERS,CUSTOM有字段CUST_ID,CUSTOMERS有字段CustID,CUSTOMERS表里的数据CUSTOM表里都有,我想把CUSTOMERS里没有,但CUSTOM表里有的数据显示到DBGRID里(用O表示),具体程序看下面:
procedure TForm1.Button1Click(Sender: TObject);
begin
 with ADOQuery1 do
 begin
  if active then close;
  sql.clear;
  sql.add('select CUST_ID from custom');
  open;
 end;
end;procedure TForm1.ADOQuery1CalcFields(DataSet: TDataSet);
begin
 with ADOQuery2 do
   begin
    if active then close;
    sql.Clear;
    sql.add('select CustID from ciscustomers');
    sql.add('where CustID='+ADOQuery1.FieldByName('CUST_ID').asstring);
    open;
    if(BOF and EOF) then
    ADOQuery1.FieldByName('name').asstring:='0'
    else
    ADOQuery1.FieldByName('name').asstring:=Fields[0].AsString;
   end;
end;但我这样写,总是报"project project1.exe raised exception
class eoleexception with message'BOF 或EOF中一个是真,或者
当前的记录被删除,所需的操作要求一个当前的记录。请指教!

解决方案 »

  1.   

    if(BOF and EOF) then
    begin
        ADOQuery1.Append;
        ADOQuery1.FieldByName('name').asstring:='0';
    end
        else
    begin
        ADOQuery1.Edit;
        ADOQuery1.FieldByName('name').asstring:=Fields[0].AsString;
    end;
       ADOQuery1.Post;
      

  2.   

    我用了你的方法 ,可还是老错误,我用Query做却可以了procedure TForm1.Button1Click(Sender: TObject);
    begin
      with Query1 do
       begin
        if active then close;
        open;
       end;
    end;procedure TForm1.Query1CalcFields(DataSet: TDataSet);begin
          with Query2 do
        begin
          if Active then close;
          SQL.Clear;
          sql.Add('select CustID from customers');
          sql.add('where CustID=:CustID');
          ParamByName('CustID').asstring:=Query1.FieldByName('CUST_ID').asstring;
          Open;
          if(BOF and EOF) then
           begin
           Query1.FieldByName('name').asstring:='00000000';
           end else
           begin
           Query1.FieldByName('name').asstring:=Fields[0].AsString;
           close;
           end;    end;
    end;
    不知道为什么,想不明白,谁知道吗