注册 登录
编程论坛 Delphi论坛

登录代码怎么写????

xytkf 发布于 2006-09-27 18:52, 764 次点击

做了一个界面不能运行代码出现错误啦...........
前台是两个字段用户名(EmployeeName),密码(Passwd):char
在确定的ONCLICK那里写代码
如下:
procedure TForm2.SpeedButton1Click(Sender: TObject);
begin
if (Edit1.Text <>'') and (Edit2.Text <>'') then
begin
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select *from EmployeeInfo where EmployeeName:=Edit1.Text and Passwd:=Edit1.Text');
//Parameters.FieldByName('employname').AsString :=Edit1.Text;
//parameters.FieldByName('password').AsString :=Edit2.Text;
Open;
if Eof then
begin
logTime := logTime+1;
if messagebox(handle,'您填写的用户名或密码不正确,是否重新输入!','出错提示',
Mb_IconInformation+Mb_Okcancel) = idcancel then
Application.Terminate;
if logTime >2 then
begin
messagebox(handle,'对不起,登录次数超过三次程序自动关闭!','非法登录',
Mb_Iconwarning+Mb_Ok);
Application.Terminate;
end;
end
else
begin

case FieldByName('LevelId').AsInteger of
0:begin
mainform.N16.Enabled:=false;
MAINFORM.N21.Enabled:=false;
end;
1:begin
MAINFORM.N9.Enabled:=false;
MAINFORM.N10.Enabled:=false;
end;
2:begin
MAINFORM.N6.Enabled:=false;
MAINFORM.N16.Enabled:=false;
MAINFORM.N7.Enabled:=false;
end;

end;
END;
END;END;END;
END.

运行会一时出错啊@!!
好像下面就是问题的错误所在:

SQL.Add('select *from EmployeeInfo where EmployeeName:=Edit1.Text and Passwd:=Edit1.Text');
//Parameters.FieldByName('employname').AsString :=Edit1.Text;
//parameters.FieldByName('password').AsString :=Edit2.Text;
Open;

2 回复
#2
volte2006-09-28 20:27
SQL.Add('select * from Employee');
SQL.Add('where EmployeeName = ' + Edit1.Text);
SQL.Add('and Passwd = ' + Edit1.Text);
Open;


上面的换成这句话!
#3
lcy20032006-09-29 15:16
try this :
SQL.Add('select * from EmployeeInfo where EmployeeName:='''+trim(Edit1.Text)+''' and Passwd:='''+trim(Edit1.Text)+'''');
1