比如我用ADOQUERY1连接TABLE1,TABLE1大致如下:
Name      PassWord
AAA       123
BBB       456
CCC       789
...
--------------------------------------------------
现在比如Edit1.text:='BBB';
在Edit2中输入数据。然后比较此记录的PassWord是否正确,若正确则YESNO为真,否则为假。

解决方案 »

  1.   

    procedure TfmLogn.BitBtn1Click(Sender: TObject);
    begin
      ADOQUERY1.Locate('Name',Edit1.text,[loCaseInsensitive,loPartialKey]);
      if Edit2.Text<>ADOQUERY1['PassWord']
      then
        begin
          Application.MessageBox('密码错误!','错误',MB_ICONERROR + MB_OK);
          Exit;
        end
        else
        begin
          ...//do something;
        end; 
    end;
      

  2.   

    建议用ADOTable来连接用户密码表。
      

  3.   

    Filter Name = Edit1.Text ;Open ;
    if Edit2.Text = FieldByName('PassWord').AsString then ...
      

  4.   

    adoquery1.sql.text:='select password from table1 where name='+''''+edit2.text+''''+'and password='+''''+edit1.text+'''';
    if adoquery1.recordcount<>0 then 
      yesno=true
    else 
      yesno=false;
    假设edit2放的是用户名
      

  5.   

    上面的代码忘了加open语句
    adoquery1.sql.text:='select password from table1 where name='+''''+edit2.text+''''+'and password='+''''+edit1.text+'''';
    adoquery1.open;
    if adoquery1.recordcount<>0 then 
      yesno=true
    else 
      yesno=false;
    假设edit2放的是用户名
      

  6.   

    或者这样写
    adoquery1.sql.text:='select count(*) from table1 where name='+''''+edit2.text+''''+'and password='+''''+edit1.text+'''';
    adoquery1.open;
    if adoquery1.fields[0].asinteger<>0 then 
      yesno=true
    else 
      yesno=false;
    假设edit2放的是用户名
      

  7.   

    谢谢各位的回答,
    我不想用SQL语句的,Filter行不行呢。
      

  8.   

    ADOTable1.Locate('Name',Edit1.text,[loCaseInsensitive,loPartialKey]);
    是一个定位函数,不是SQL语句。
      

  9.   

    var
      str1, str2: String;begin
      with adoquery1 do
      begin
        Active := False;
        sql.text:='select password from table1 where  name=:str1 and password=:str2';
        Parameters[0].value := edit1.text;
        Parameters[1].Value := edit2.text;   
        Active := true;
       if recordcount>0 then 
         yesno=true
       else 
        yesno=false;
      end;
    end;
      

  10.   

    Re:谢谢各位的回答,
    我不想用SQL语句的,Filter行不行呢。
    var
    str1, str2: string;begin
      str1 := 'name';
      str2 := 'password';
      with adoquery1 do
      begin
    ..............
        filtered := true;
        filter:='str1='+''''+edit2.text+''''+'and str2='+''''+edit1.text+'''';
        if recordCount>0 then 
          yesno=true
        else 
          yesno=false;
        end;
    end;