delphi源码 基础源码-连接数据库,验证登录信息  
官方Delphi 学习QQ群: 682628230(三千人)\n
频道

delphi源码 基础源码-连接数据库,验证登录信息


delphi源码 基础源码-连接数据库,验证登录信息

procedure TForm1.Image4Click(Sender: TObject);
var
ADOQuery1: TADOQuery;
begin
{数据库操作:判断用户和密码是否正确}
if (edit1.Text<>'') and (edit2.Text<>'') then
begin
ChDir(ExtractFilePath(Application.ExeName));
ChDir('..');
ExeRoot := GetCurrentDir;
DataFile := GetCurrentDir+'\Data\dzyv1.mdb';
ADOQuery1:= TADOQuery.Create(self);
ADOQuery1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+DataFile+';Persist Security Info=False;';
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from t_user where user_name="'+edit1.Text+'" and user_pass="'+edit2.Text+'" ');
ADOQuery1.Open;
if ADOQuery1.Eof then
begin
LogTimes := LogTimes+1;
if messagebox(handle,'您填写的用户或密码有错误!是否重新输入?','出错提示',mb_iconinformation+mb_okcancel)=IDcancel then application.Terminate;
if LogTimes>=3 then
begin
messagebox(handle,'对不起,登录次数超过3次,程序自动关闭!','非法登录',MB_ICONWARNING+mb_ok);
application.Terminate;
end;
end
else
begin
{用户和密码正确,登录成功}
UserType := ADOQuery1.FieldByName('user_type').AsString;
UserName := ADOQuery1.FieldByName('user_name').AsString;
LogTimes := 0;
ADOQuery1.Free;
Form1.Hide;
form2.ShowModal;
end;
end
else
messagebox(handle,'您没有填写用户和密码!','出错提示',mb_iconinformation+mb_ok)
end;
推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.048381090164185 seconds