做登陆窗体时候加了个combobox控件;
下面是我的代码:
procedure TForm2.SpeedButton1Click(Sender: TObject);
begin
with adoquery1 do
 begin
 close;
 sql.Clear;
 sql.Add('select * from 管理员表 where 用户名=:na ,权限=:sa and 密码=:pa');
 parameters.ParamByName('na').Value:=edit1.Text;
 parameters.ParamByName('pa').Value:=edit2.Text;
 open;
 if recordcount=0 then
 begin
 application.MessageBox('您输入的用户名或密码不正确,请重新输入!','系统提示',0+64);
 edit1.Text:='';
 edit2.Text:='';
 edit1.SetFocus;
 exit;
但是权限不知道改怎么处理,谁能告诉我填加什么代码?

解决方案 »

  1.   

    sql.Add('select * from 管理员表 where (用户名=:na) and (权限=:sa) and (密码=:pa)');
     parameters.ParamByName('na').Value:=QuotedStr(edit1.Text);
     parameters.ParamByName('sa').Value:=IntToStr(Combobox1.ItemIndex);
     parameters.ParamByName('pa').Value:=QuotedStr(edit2.Text);
     open;
     if recordcount<1 then
     begin
     application.MessageBox('用户名/密码不正确或无此权限,请重新输入!','系统提示',0+64);
    不一定对,试试看
      

  2.   

    procedure TForm2.SpeedButton1Click(Sender: TObject);
    begin
    with adoquery1 do
     begin
     close;
     sql.Clear;
     sql.Add('select * from 管理员表 where 用户名=:na ,权限=isnull(:sa,权限) and 密码=:pa');
     parameters.ParamByName('na').Value:=edit1.Text;
     parameters.ParamByName('pa').Value:=edit2.Text;
     open;
     if recordcount=0 then
     begin
     application.MessageBox('您输入的用户名或密码不正确,请重新输入!','系统提示',0+64);
     edit1.Text:='';
     edit2.Text:='';
     edit1.SetFocus;
     exit;