当前位置:编程学习 > Delphi >>

delphi adoquery 查询的问题~

做一个登陆系统

procedure check(rdb:string;raccount:string);
begin
  with form1 do
    begin
      adoquery1.Close;
      adoquery1.Parameters.ParamByName('db').Value :=rdb;
      adoquery1.Parameters.ParamByName('account').Value :=raccount;
      adoquery1.Open;
      if edit2.Text=adoquery1['password']  then pass:=true
        else showmessage('密码错误,如忘记密码请联系管理员!');

    end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  case radiogroup1.ItemIndex of
  0: check('teacher',edit1.text);
  1: check('student',edit1.Text);
  2: check('master',edit1.Text);
  end;
  if pass then
    begin form1.Close;
          form2.Show;
    end;
end;

 

选中哪个,就在哪个表里面搜

adoquery里的sql:

select password from :db where account=:account

 

但运行点登陆后  显示 “必须声明表变量“@P1 ””  难道sql里面还要建立什么呢?

补充:

procedure check(db:string;account:string);
begin
  with form1 do
    begin
      adoquery1.Close;
      adoquery1.SQL.Clear;
      adoquery1.SQL.Add('select password from '+db+' where account=''+account+''');
      adoquery1.Open;
      if edit2.Text=adoquery1.FieldByName('password')   then pass:=true
        else application.messagebox('密码错误,如忘记密码请联系管理员!','密码错误!',mb_ok);

    end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  case radiogroup1.ItemIndex of
  0: check('teacher',edit1.text);
  1: check('student',edit1.Text);
  2: check('master',edit1.Text);
  end;
  if pass then
    begin form1.Close;
          form2.Show;
    end;
end;

 

能运行了,但为什么输入对的也是显示密码错误呀。。

sql  student表里    account:wangming   password:11111

按这个输入,说密码错误。。。求解

追问:那要是直接往  属性里的 sql里写应该怎么写呢?
答案:

别直接写在控件属性里面。

你可以这么写

with adoquery1 do

begin

Close;

SQL.Clear;

SQL.Text:='Select * from '+rdb+' where account='+Raccount;  //这里要看你的account是什么类的,如果是数值类的,就是上面这种写法,如果是字符类的,则'Select * from '+rdb+' where account='''+Raccount+'''';

open;

end;

if Edit2.text=Adoquery1.FieldByName('PassWord').AsString then

pass:=True;

sql错误吧,那里面的写法有误
adoquery1.SQL.Add(‘select password from’ + db + ' where accout =' + account)

上一个:一个简单的delphi问题
下一个:学习delphi有发展么?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,