各位大哥,小弟初学delphi,现在想做一个小程序,但一开始就遇到问题了,我想利用adoquery、adoconnection、datasource,然后我想利用 dbComboBox 从数据库中取出所有的用户名,并显示在下拉框中,然后判断用户输入在dbEdit中的密码与数据库中的密码是否一致,以达到登录的目的,希望能够发一个完整的源代码给我,另外数据库的连接是在程序中写入还是在属性中直接用ADOConnection来实现呢?谢谢我的E-mail : [email protected] [email protected]
解决方案 »
- treeview显示的问题
- 请问如何在dll中使用多线程机制。
- frames的问题
- 如何用程序啟動NT服務?
- 如何表达money型的跟integer型的乘法?
- 在delphi當中如何控制excel當中圖片的大小。。急呀。。。。
- 请问以下查询语句怎样写?
- 如何动态建立一个表,然后操作他?
- Exception EStyleEngineException in module vcl180.bplClass 'TRzEditStyleHook' is
- 我的socketconnection老连不上application server,这是怎么回事?
- 有一行代码不懂,明白的请进!
- 难!是否可以检测到其他程序产生的异常,并且强行将他结束?
begin
end
打开程序界面代码
else
begin
停留在登陆窗口
end;最好不用DBEDIT
用EDIT可以直接进行判断
数据库连接一般用ADOConnection的属性设置来实现
程序就将有户数据表的指针位置移到
想一的位置上,
当用户输入密码后,敲“登陆键”时
就对比当前用户数据表中“密码”字
段的置是否与用户输入的一致啊!
procedure TFrmDl.BtoOkClick(Sender: TObject);
begin
Inlogin:=Inlogin+1;
//查找是否有此用户存在并且密码是否正确
with DmMain.ADOQDl do
begin
sql.Clear;
sql.Add('select * from czyb where ');
sql.Add('czyxm='''+cbxm.Text+''' and '+'czymm='''+edmm.Text+'''');
open;
//如果不存在
if eof then
begin
//如果输入错误超过三次
if Inlogin>3 then
begin
showmessage('已经输入三次错误,退出系统!');
//退出系统
application.Terminate;
end
else
begin
showmessage('输入错误,请重新输入!');
cbxm.SetFocus;
end;
end
else
begin //保存登录时的用户编号和姓名
IsUserBh:=fieldbyname('czybm').AsString;
IsUserName:=fieldbyname('czyxm').AsString;
FrmDl.Close;
Application.CreateForm(TFrmlb, Frmlb);
frmlb.Visible:=false;
frmlb.ShowModal;
end;
end;
end;
adoquery.first;
while not adoquery.eof do
begin
combobox1.item.add(adoquery.fieldbyname('字段名').asstring);
adoquery.next
end;
with ADOTable1do
begin
Open ;
Edit;
First;
DBComboBox1.Items.Clear;
While Not Eof Do
begin
DBComboBox1.Items.Add(FieldByName('字段名').AsString);
Next;
end;效应密码时我想最好用locate,界面上最好用edit,
DataSource1.DataSet.Locate('用户名;密码',VarArrayOf([DBComboBox1.text,edit1.text]),[loCaseInsensitive])
procedure Tcldbf.DataModuleCreate(Sender: TObject);
var
inif:Tinifile;
a,b:array [0..5] of string;
begin
main.door:=false;
a[0]:='Provider=';
a[1]:='Data Source=';
a[2]:='Initial Catalog=';
a[3]:='User ID=';
a[4]:='Password=';
a[5]:='Persist Security Info='; maindbf.Connected:=false;
b[0]:='SQLOLEDB.1';
b[1]:='server';
b[2]:='test';
b[3]:='sa';
b[4]:='';
b[5]:='False';
inif:=Tinifile.Create(extractfilepath(application.ExeName)+'configure.ini');
try
b[0]:=inif.ReadString('DATABASE','driver',b[0]);
b[1]:=inif.ReadString('DATABASE','server',b[1]);
b[2]:=inif.ReadString('DATABASE','database',b[2]);
b[3]:=inif.ReadString('DATABASE','username',b[3]);
b[4]:=inif.ReadString('DATABASE','password',b[4]);
b[5]:=inif.ReadString('DATABASE','psi',b[5]);
finally
inif.free;
end;
b[4]:=Encrypt(b[4],3);
b[4]:=copy(b[4],1,pos('zjsxfaw',b[4])-1);
maindbf.ConnectionString:=a[0]+b[0]+';'+a[1]+b[1]+';'+a[2]+b[2]+';'+a[3]+b[3]+';'+a[4]+b[4]+';'+a[5]+b[5];
try maindbf.Connected:=true;
main.door:=true;
except showmessage('后台管理配置错误,请重新设置!');
end;
//以上为ADO连接
end;登录界面最好在工程文件里控制,如下:
program Project1;uses
Forms,
main_try in 'main_try.pas' {main},
wait_sys in 'wait_sys.pas' {wait},
about_sys in 'about_sys.pas' {about},
login_zj in 'login_zj.pas' {login},
db_zj in 'db_zj.pas' {cldbf: TDataModule};{$R *.res}begin
Application.Initialize;
wait:=Twait.create(application);
wait.ProgressBar1.Max:=100; wait.Show;
application.ProcessMessages; ///////////
wait.Update;
// wait.name_lbl.Caption:='读取参数...';
wait.company_lbl.Caption:='正在初始化...';
wait.update;
Application.CreateForm(Tmain, main);
wait.ProgressBar1.StepBy(25);
wait.company_lbl.Caption:='正在建立数据库连接...';
wait.update;
Application.CreateForm(Tcldbf, cldbf);
wait.ProgressBar1.StepBy(50);
if main.door then
begin
wait.company_lbl.Caption:='数据库连接成功!';
wait.update;
Application.CreateForm(Tabout, about); login:=Tlogin.Create(application); //用户名密码窗体
wait.ProgressBar1.StepBy(25);
wait.hide;
wait.free; login.ShowModal; //显示密码窗体
if login.con then
begin
Application.Run;
end;
end
else Application.Terminate;
end.