我编了一段小代码,大家帮忙看看哪里出错了  
procedure  TForm1.CheckBox1Click(Sender:  TObject);  
var  
 s:  integer;  
begin  
     adoconnection1.Connected:=true;  
     adoquery1.Active:=true;  
     adoquery1.SQL.Add('select  VHour  from  CardType  where  VPerson=:1');  
     s:=adoquery1.Fieldbyname('VHour').AsInteger;  
     adoquery1.ExecSQL;  
     memo1.Lines.Add(inttostr(s));  
end;  
运行后出现这个错误。  
ADOquery1:Field  'VHour'  not  found  
其中'select  VHour  from  CardType  where  VPerson=:1'这一句没有什么问题。

解决方案 »

  1.   

    procedure TForm1.CheckBox1Click(Sender: TObject);
    var
    s: integer;
    begin
       adoconnection1.Connected:=true;
       with adoquery1 do
       begin
          Close;
          SQL.Clear;
          SQL.Add('select VHour from CardType where VPerson=:1');
          Open;
          memo1.Lines.Add(Fieldbyname('VHour').AsString);
       end;
    end;
      

  2.   

    數據機還沒打開你就取數據了,當然不對了.procedure  TForm1.CheckBox1Click(Sender:  TObject);  
    var  
     s:  integer;  
    begin  
         adoconnection1.Connected:=true;  
         adoquery1.Active:=false;  
         adoquery1.SQL.Clear();
         adoquery1.SQL.Add('select  VHour  from  CardType  where  VPerson=:1');  
         adoquery1.Open();
         s:=adoquery1.Fieldbyname('VHour').AsInteger;  
         memo1.Lines.Add(inttostr(s));  
    end;  找本基礎點的書看看吧
      

  3.   

    另外,你定义了一个参数,所以要在open前加 adoquery1.Parameters[0].Value='VPerson的值';
      

  4.   

    SQL.Add('select VHour from CardType where VPerson=1');