procedure TForm1.Edit2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if edit1.Text='' then
begin
application.MessageBox('用户名不能为空!','警告',mb_ok);
edit1.SetFocus;
end;end;procedure TForm1.Button1Click(Sender: TObject);
var
f1:Tform2;
f2:Tform3;
begin
if edit2.Text='' then
begin
application.MessageBox('密码不能为空!','警告',mb_ok);
edit2.SetFocus;
end
else
begin adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from users where ID=:nu and password=:pa');
adoquery1.Parameters[0].Value:=Edit1.Text;
adoquery1.Parameters[1].Value:=Edit2.Text;
adoquery1.open;
end;
if adoquery1.RecordCount>0 then
begin
if Trim(adoquery1.FieldByName('admin').AsString)='true' then
begin
form1.Hide;
f1:=Tform2.Create(application);
try
f1.showmodal;
finally
f1.free;
end;
end else if Trim(adoquery1.FieldByName('admin').AsString)='false' then
begin
form1.Hide;
f2:=Tform3.Create(application);
f2.show;
end;
end
else
begin
showmessage('对不起,该用户不存在!');
form1.Edit1.Text:='';
form1.Edit2.Text:='';
end;
end;
刚刚学delphi,很多还不会,关键是查询用户名和密码那一点。哪位高手指点一下,在线等~~~~~
Shift: TShiftState; X, Y: Integer);
begin
if edit1.Text='' then
begin
application.MessageBox('用户名不能为空!','警告',mb_ok);
edit1.SetFocus;
end;end;procedure TForm1.Button1Click(Sender: TObject);
var
f1:Tform2;
f2:Tform3;
begin
if edit2.Text='' then
begin
application.MessageBox('密码不能为空!','警告',mb_ok);
edit2.SetFocus;
end
else
begin adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from users where ID=:nu and password=:pa');
adoquery1.Parameters[0].Value:=Edit1.Text;
adoquery1.Parameters[1].Value:=Edit2.Text;
adoquery1.open;
end;
if adoquery1.RecordCount>0 then
begin
if Trim(adoquery1.FieldByName('admin').AsString)='true' then
begin
form1.Hide;
f1:=Tform2.Create(application);
try
f1.showmodal;
finally
f1.free;
end;
end else if Trim(adoquery1.FieldByName('admin').AsString)='false' then
begin
form1.Hide;
f2:=Tform3.Create(application);
f2.show;
end;
end
else
begin
showmessage('对不起,该用户不存在!');
form1.Edit1.Text:='';
form1.Edit2.Text:='';
end;
end;
刚刚学delphi,很多还不会,关键是查询用户名和密码那一点。哪位高手指点一下,在线等~~~~~
var
f1:Tform2;
f2:Tform3;
begin
if edit2.Text='' then
begin
application.MessageBox('密码不能为空!','警告',mb_ok);
edit2.SetFocus;
exit;
end;
//else
begin adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from users where ID=:nu and password=:pa');
adoquery1.Parameters[0].Value:=QuotedStr(Edit1.Text);
adoquery1.Parameters[1].Value:=QuotedStr(Edit2.Text);
adoquery1.open;
end;
if adoquery1.RecordCount>0 then
begin
if Trim(adoquery1.FieldByName('admin').AsString)='true' then
begin
form1.Hide;
f1:=Tform2.Create(application);
try
f1.showmodal;
finally
f1.free;
end;
end
else if Trim(adoquery1.FieldByName('admin').AsString)='false' then
begin
form1.Hide;
f2:=Tform3.Create(application);
f2.show;
end;
end
else
begin
showmessage('对不起,该用户不存在!');
form1.Edit1.Text:='';
form1.Edit2.Text:='';
end;
end;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from users where ID=:nu and password=:pa');
adoquery1.Parameters[nu].Value:=Edit1.Text;
adoquery1.Parameters[pa].Value:=Edit2.Text;
adoquery1.open;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from users where ID=:nu and password=:pa');
adoquery1.Parameters[0].Value:=QuotedStr(Edit1.Text);
adoquery1.Parameters[1].Value:=QuotedStr(Edit2.Text);
adoquery1.open;可以改成adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from users where ID='+edit1.text+' and password='''+edit2,text+'''');
adoquery1.open;
begin
这一句是什么意思啊,好像意义不大只要 if adoquery1.RecordCount>0 then 这个条件为真就显示窗口就好了吧?