很急,很急的问题

jackie8008 2004-08-11 09:14:38
我以前没有用过deophi,向解决如下的问题
有一个数据库equip里面有一张表user;
现在做一个登陆的程序,登陆时连接数据库,登陆名称和登陆密码输入与数据库user表的数据相比较,对了就进入查询,不对就抱错,请问登陆时怎么做?
给出源码,
很急,很急,马上就要用,解决了给100分
...全文
144 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
tarim 2004-08-13
  • 打赏
  • 举报
回复
看了以上的答案还没有作出来,那么回去看书是最好的解决办法
才子鸣 2004-08-13
  • 打赏
  • 举报
回复
up
cctv6012cn 2004-08-13
  • 打赏
  • 举报
回复
楼主。要解决问题,请见上面几位的源码!!!你改一下就可以用了哟
jian23cn 2004-08-13
  • 打赏
  • 举报
回复
楼主在做如下操作时:
ADOConnection1.ConnectionString:=st;
ADOConnection1.Connected:=true;
必须保证在设计的时候ADOConnection1的Connected为False;否则就会出现上面所说的“对想打开是操作不被允许

xxzhanghao 2004-08-13
  • 打赏
  • 举报
回复
其实实现这个很简单 上面有几位大哥写的不错啊
yufly 2004-08-13
  • 打赏
  • 举报
回复
procedure TFrmLogin.BtnLoginClick(Sender: TObject);
begin
DataModule1.UserTable.Active:=true;
if EdtUser.Text='' then
begin
ShowMessage('请输入用户名!');
EdtUser.SetFocus;
exit;
end;
if DataModule1.UserTable.Locate('username;userpwd',VarArrayOf([EdtUser.Text,EdtPassword.Text]),
[]) then
begin
UName:=EdtUser.Text;
Upwd:=EdtPassword.Text;
FormMain.Show;
FrmLogin.Hide;
end
else
begin
ShowMessage('请输入正确的密码');
EdtPassword.SetFocus;
exit;
end;
end;
hongqi162 2004-08-11
  • 打赏
  • 举报
回复
ADOConnection1.Connected:=true;
>> adotable1.Connection:=ADOConnection1;
>> adotable1.TableName:=user;
if not ADOTable1.Locate('username',username,[])then
jackie8008 2004-08-11
  • 打赏
  • 举报
回复
救救我把
jackie8008 2004-08-11
  • 打赏
  • 举报
回复
我这样做怎么发生错误
procedure Tlogin.LoginBtnClick(Sender: TObject);
begin
username:=login.Edit1.Text;
paswd:=login.Edit2.Text;
pathst:=getcurrentdir()+'\mdb\equip.mdb;';
st:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\EquipManage\mdb\equip.mdb;Persist Security Info=False';
ADOConnection1.ConnectionString:=st;
ADOConnection1.Connected:=true;
if not ADOTable1.Locate('username',username,[])then
begin
FLogError.ShowModal;
ADOTable1.Close;
ADOConnection1.Close;
end
else if ADOTable1.FieldValues['pswd']=paswd then
begin
FsearchG1.ShowModal;
login.Hide;
ADOTable1.Close;
ADOConnection1.Close;
end
else begin
FLogError.ShowModal;
ADOTable1.Close;
ADOConnection1.Close;
end;


end;

end.
说是什么对想打开是操作不被允许
metro 2004-08-11
  • 打赏
  • 举报
回复
// edit1.text为用户名输入框;
// edit2.text为密码输入框
user.Filter:='id='''+edit1.Text+'''';
user.Filtered:=true;
user.Open;
if user.RecordCount=1 then //判断登陆名
begin
if user['passwd']=edit2.Text then
begin
....查询
end
else showmessage('密码不对!');
end
else showmessage('无此用户!')
orchidbing 2004-08-11
  • 打赏
  • 举报
回复
我也来一个
unit Unit5;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables;

type
TForm5 = class(TForm)
Button1: TButton;
GroupBox1: TGroupBox;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Table1: TTable;
procedure Button1Click(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form5: TForm5;
sUserID,sUserPW: string;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm5.Button1Click(Sender: TObject);
begin
try
table1.Filter:='name='''+edit1.text+'''';
table1.Filtered:=true;
table1.Open;
Except
Application.MessageBox('数据库连接失败,请于系统管理员联系。','数据库连接错误!',MB_OK);
Application.Terminate;
end;
if table1.recordcount=1 then
begin
if table1['password']=edit2.text then
begin
sUserID := Trim(edit1.Text);
sUserPW := Trim(edit2.Text);
self.ModalResult:=mrOK;
end
else
begin
Application.MessageBox('密码输入有误,请确认密码!','密码不正确!',MB_OK);
edit2.SetFocus;
end;
end
else Application.MessageBox('请确认用户名是否正确!','无此用户!',MB_OK); edit1.SetFocus;
end;

procedure TForm5.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then { 如 果 按 下 了 回 车 键 }
begin
Key := #0; { 吃 掉 回 车 键 }
Perform(WM_NEXTDLGCTL,0,0); { 移 动 到 下 一 个 控 制 }
end;
end;

procedure TForm5.Button2Click(Sender: TObject);
begin
close;
end;

end.
insert2003 2004-08-11
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
ADOTable1: TADOTable;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if not adotable1.Locate('name',edit1.Text,[]) then
showmessage('不存在这个用户,登陆失败')
else
if adotable1.FieldValues['password']=edit2.Text then
begin
form2.Show;
form1.Hide;
end
else
begin
showmessage('密码错误,请从新登陆');
application.Terminate;
end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
form1.close;
end;

end.

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧