以下是代码,帮帮忙看下吧procedure TLoginForm.Button1Click(Sender: TObject);
var
sqlStr:String;
beginif  (IdEdit.Text='')  or  (PwEdit.Text='') then
      begin
          showmessage('请输入用户名和用户密码');
          exit;
      end;
      with  ADoQuery1    do
          begin
          close;
              SQL.Clear;
              sqlStr:='select *  from 用户管理  where( ID='''+IdEdit.Text+''')and( PW='''+PwEdit.Text+''')';
              SQL.Add(sqlStr);
               ExecSQL;
              if  ADoQuery1.Recordset.RecordCount<>0   then
                  begin
                  LoginForm.Hide;
                  mainForm.ShowModal;
                  mainForm.Visible:=true;
                  LoginForm.Close;
                  end
                  else
                      begin
                         showmessage('用户'''+IdEdit.Text+'''是非法用户');
                          exit;
                      end;   
          end;   end;procedure TLoginForm.Button2Click(Sender: TObject);
begin
 close;
end;end.

解决方案 »

  1.   

     ExecSQL;   //改为  open;
      
      

  2.   

    with  ADoQuery1    do 
              begin 
              close; 
                  SQL.Clear; 
                  sqlStr:= 'select *  from 用户管理  where( ID= ' ' '+IdEdit.Text+ ' ' ')and( PW= ' ' '+PwEdit.Text+ ' ' ') '; 
                  SQL.Add(sqlStr); 
                    open;// 
              end;//
                  if  ADoQuery1.Recordset.RecordCount < >0   then 
                      begin 
                      LoginForm.Hide; 
                      mainForm.ShowModal; 
                      mainForm.Visible:=true; 
                      LoginForm.Close; 
                      end 
                      else 
                          begin 
                             showmessage( '用户 ' ' '+IdEdit.Text+ ' ' '是非法用户 '); 
                              exit; 
                          end;    
              //end;    
      

  3.   

    ExecSQL
    一般是用来之行sql 的比如 insert,update 等没返回数据集的sql语句。 open 
    用来有返回数据集的sql语句。
      

  4.   

     sqlStr:=  'select *  from 用户管理  where(ID='''+IdEdit.Text+''')and( PW='''+PwEdit.Text+''')'; 题外话:
      如果我在IdEdit或者PwEdit里头输入 or 1>0,你的帐号密码验证这条防线就失去了意义。帐号密码验证方式应该是根据用户帐号名称,取出帐号及密码,然后做校验。
      

  5.   

    你确定输入or 1>0可以过他的验证吗?那个进去后是个字符串啊.
      

  6.   

    楼上的,IdEdit和PwEdit的Text值分别是:
    xxx' or 1>0 or ID='xxx
    xxx' or 1>0 or PW='xxx
    校验还有意义吗?如下:
    strSql := 'select *  from 用户管理  where(ID= ''xxx'' or 1>0 or ID=''xxx'')and
    (PW=''xxx'' or 1>0 or PW=''xxx''';