procedure TForm2.Button1Click(Sender: TObject);
begin
if   xx.ItemIndex =0  then
query1.SQL.Clear ;
query1.SQL.Add('select * from renyuanbiao where username='''+edit1.Text+'''' ) ;
query1.open  ;
if   xx.ItemIndex=1 then
query1.SQL.Clear ;
query1.SQL.Add('select * from renyuanbiao where name='''+edit1.Text+'''' ) ;
query1.open  ;
end;

解决方案 »

  1.   

    query1.SQL.Clear;
    前面最好加上一句:
    query1.Close;
      

  2.   

    不知道有啥问题,不过楼主可以这样写procedure TForm2.Button1Click(Sender: TObject); 
    begin 
      case xx.ItemIndex of
        0:begin
            with Query1 do
            begin
              SQL.Clear; 
              SQL.Add('SELECT * FROM RenYuanBiao WHERE UserName='''+Edit1.Text+''''); 
              open; 
            end;
          end;
        1:begin
            with Query1 do
            begin
              SQL.Clear; 
              SQL.Add('SELECT * FROM RenYuanBiao WHERE Name='''+Edit1.Text+''''); 
              open; 
            end;
          end;
      end;
    是不是通不过啊?query1.SQL.Add('select * from renyuanbiao where username='''+edit1.Text+'''' ) ; 
    query1.SQL.Add('select * from renyuanbiao where name='''+edit1.Text+'''' ) ; 
    改成这样
    query1.SQL.Add('select * from renyuanbiao where username='+''''+edit1.Text+'''') ; 
    query1.SQL.Add('select * from renyuanbiao where name='+''''+edit1.Text+'''') ; 注意代码写的规范些,区分大小写,修改起来会方便
      

  3.   

    [Error] Unit2.pas(62): ';' expected but '.' found
    [Error] Unit2.pas(70): Declaration expected but end of file found
    [Fatal Error] cwxt.dpr(15): Could not compile used unit 'Unit2.pas'
      

  4.   

    在3楼代码最后要加一个
    end;
      

  5.   


    procedure TForm2.Button1Click(Sender: TObject); 
    begin 
    if   xx.ItemIndex =0  then 
       begin
       query1.SQL.Clear ; 
       query1.SQL.Add('select * from renyuanbiao where    username='''+edit1.Text+'''' ) ; 
       query1.open  ; 
       end;
    if   xx.ItemIndex=1 then 
       begin
       query1.SQL.Clear ; 
       query1.SQL.Add('select * from renyuanbiao where name='''+edit1.Text+'''' ) ; 
       query1.open  ; 
       end;
    end; 
      

  6.   

    谢谢了,可以了
    为什么还要加个end啊
      

  7.   

    不光是加个END.在DEPHI中 if ...then 如果后面是二条以上一定要用上begin... end 
      

  8.   

    procedure TForm2.Button1Click(Sender: TObject); 
    begin 
    if   xx.ItemIndex =0  then 
    begin
    query1.close;
    query1.SQL.Clear ; 
    query1.SQL.Add('select * from renyuanbiao where username='''+edit1.Text+'''' ) ; 
    query1.open;
    end; 
    if   xx.ItemIndex=1 then 
    begin
    query1.close;
    query1.SQL.Clear ; 
    query1.SQL.Add('select * from renyuanbiao where name='''+edit1.Text+'''' ) ; 
    query1.open;
    end; 
    end; 
      

  9.   

    with Query1 do 
    begin 
      IF Active Then Close;//记得要关闭活动连接
      SQL.Clear;  
      SQL.Add('SELECT * FROM RenYuanBiao WHERE Name='''+Edit1.Text+'''');  
      open;  
    end; 
      

  10.   


    procedure TForm2.Button1Click(Sender: TObject); 
    begin 
        if xx.ItemIndex =0 then 
        begin
            query1.SQL.Clear ; 
            query1.SQL.Add('select * from renyuanbiao where username='''+edit1.Text+'''' ); 
            query1.open;
        end; 
        if xx.ItemIndex=1 then 
        begin
            query1.SQL.Clear ; 
            query1.SQL.Add('select * from renyuanbiao where name='''+edit1.Text+'''' ); 
            query1.open; 
        end; 
    end;
    最后加end;
    希望楼主写代码时养成一个良好的编程风格,包括缩进,命名等等,对你自己排错或看代码也容易很多!
      

  11.   

    procedure TForm2.Button1Click(Sender: TObject); 
    begin 
      query1.Close; 
      query1.SQL.Clear ; 
      if   xx.ItemIndex =0  then 
        query1.SQL.Add('select * from renyuanbiao where    username='''+edit1.Text+'''' ) ; 
      else if   xx.ItemIndex=1 then 
       query1.SQL.Add('select * from renyuanbiao where name='''+edit1.Text+'''' ) ;   query1.open  ; 
    end; 
      

  12.   

    procedure TForm2.Button1Click(Sender: TObject);  
    procedure LoadUser;
    begin
      With Query1 do
      begin
       Close;
       Sql.Clear;
       Sql.Text:='select * from renyuanbiao';
       Open; 
      end;
    end;
    begin  
       LoadUser;
       Case  xx.ItemIndex of
         0:Query1.Filter:='Username='+QuotedStr(edit1.Text);//用Filter即可
         1:
       end;
    end;