下面这段程序是密码登录时我只用了一个控件Ttable做的查询用户名和密码,如用户名存在时可登录,不存在时显示错误。不过,运行时就了错了,哪位高手帮我看看:              1、是否只用TABLE控件是不行的,还用别的?
              2、我的数据库别名为sysuser,库表为userpwd
              3、库表的三个字段分别为:userID,userPwd,userLev到底是怎么回事啊?
     With Table1 do                 //从数据库表中查询
        begin
            active:=true;
             a_flag:=locate('userID',Edit1.Text,[loCaseInsensitive]); //判断用户名是否存在
            if (a_flag=true);
             then begin
                   KeyValues:=Lookup('UserID',Edit1.text,"UserPwd');      //判断密码与用户名是否匹配                   if (Edit2.Text=KeyValues)            //密码正确时显示
                   then begin
                   showmessage('欢迎'+'用户'+Edit1.Text+'登录本系统');
                           login_f.Hide;
                         F_main.ShowModal;
                     end                   else begin                                  //密码错误时显示并清空
                         showmessage('密码不正确,请重新输入');
                        Edit1.Text:='';
                         Edit2.Text:='';
                        exit;
                  end
      end      else begin
      showmessage('用户名不存,请确认');
      Edit1.Text:='';
     Edit2.Text:='';
      exit;
     end;
   end;

解决方案 »

  1.   

    你将EDIT1。TEXT、EDIT2。TEXT前加TRIM试一下。
      

  2.   

    最好不要用table,用query好处理。
      

  3.   

    请问要query怎么处理上面改写并实现上面的代码呢???请帮忙详细写出啊!我是楼主。
      

  4.   

    1.用adoquery.
    2.加TRIM()
    3.密码要加密...
    4.不要用lookup,用locate[密码大小写不要区分,[loPartialKey]
      

  5.   

    //为了防止用户利用漏洞 请在edit1地keypress中写
    //if( key='''') or (key='"') then key=#0;
    //下面的代码是用查询控件查询的 需要设一下databasename 其他的不要管
    query1.close;
    query1.sql.clear;
    query1.sql.add('select * from userpwd where userid='''+edit1.text);
    query1.sql.add(''' and userpwd='''+edit2.text+'''');
    query1.open ;
    if not query1.eof then
    begin
    showmessage('欢迎'+'用户'+Edit1.Text+'登录本系统');
                               login_f.Hide;
                             F_main.ShowModal;
                         
    end
    else
    begin
    showmessage('密码不正确,请重新输入');
                            Edit1.Text:='';
                             Edit2.Text:='';
                            exit;
    end;