这样的我在SQL建了个表,是用于登陆界面的用户名和密码查询功能的实现上的,可是表建了怎么输入表值呢?就是说用户点击查询按钮就能看见用户列表然后自己选择。密码当然要用户自己输入了,又怎么样对应通过验证呢???
对我来说一直想不通请高手指教,谢谢,能不能不粘帖一段代码,用人类的语言说给我听听:)
真是麻烦了,谢谢谢谢谢谢谢谢,对我来说太重要了。真是麻烦了谢谢大家。
对我来说一直想不通请高手指教,谢谢,能不能不粘帖一段代码,用人类的语言说给我听听:)
真是麻烦了,谢谢谢谢谢谢谢谢,对我来说太重要了。真是麻烦了谢谢大家。
用户列表:你想要怎样的效果,列表还是下拉菜单前者用DBLookupListBox后者用DBLookupComboBox(都不用代码哦)。当输入密码时只要比较密码字段与输入框中是否相同就行了。因为你不要代码,所以也只能解释到这样了
var
UserName, PassWord: string;
begin
with ADOConnection1 do
begin
Close;
ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=(local)';
Open;
end;
with ADOQuery1 do
begin
Close;
Connection := ADOConnection1;
SQL.Clear;
SQL.Add('select * from UserTable');
Open;
while not Eof do
begin
ListBox1.Items.Add(FieldByName('UserName').AsString);
Next;
end;
end; with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from UserTable');
SQL.Add('Where UserName =: uUserName');
SQL.Add(' and PassWord =: uPassWord');
Parameters.ParamByName('uUserName').Value := UserName;
Parameters.ParamByName('uPassWord').Value := PassWord;
Open;
end; if ADOQuery1.RecordCount = 1 then
ShowMessage(Format('用户 %s 密码正确', [UserName]))
else
ShowMessage(Format('用户 %s 密码错误', [UserName]));
end;
其中UserTable是你在SQL数据库中建立的用户表, UserName为该表中的用户名字段, PassWord为该用户的密码.
1 张三 大连 小喽罗 ....
2 李四 北京 炮灰 ....
......
登陆No.:_____ 密码:______ |确认| |退出|
_______________________________________________________________根据上面的列表,用户输入No.和密码就可以登录
我感觉程序不要过多的依赖鼠标,点来点去还不如按部就班的敲键盘舒服.
var
now_pass: String;
begin
with adoquery1 do
begin
Close;
Sql.Clear;
Sql.Add('Select CZYGH, CZYMM, CZYMC, BMH From op_info');
Sql.Add(' Where CZYGH = ''' + egh.Text + '''' + ' and CZYMM = ''' + epwd.Text + '''');
try
Open;
sWorkNo := FieldByName('CZYGH').AsString;
sUserName := FieldByName('CZYMC').AsString;
bumenno := FieldByName('BMH').AsInteger;
Close;
except
//MessageBox(0,'总在最前','提示',MB_ICONINFORMATION + MB_OK);
Application.MessageBox('系统出错!!!', '失败信息', MB_OK);
ModalResult := mrCancel;
exit;
end;
end;
if sWorkNo <> '' then
begin
with datamodule1 do
begin
ModalResult := mrOk;
sPassword := now_pass;
// MainFrm.StatusBar.Panels[1].Text := '操作员:' + sUserName;
end;
with adoquery1 do
begin
Close;
Sql.Clear;
Sql.Add('Insert Into login(CZYGH, CZNRH, CZSJ)');
Sql.Add(' Values (:a, :b, :c)');
Parameters.ParamValues['a']:=sWorkNo;
Parameters.ParamValues['b']:=1;
SP.Prepared:=true;
try
SP.ExecProc;
Parameters.ParamValues['c']:= SP.Parameters.ParamValues['@RetDateTime']; //Get DateTime from Server
//dLoginTime:=parameters.ParamValues['a'];
ExecSql;
//ZXWYGLXT:=TZXWYGLXT.Create(Application);
//ZXWYGLXT.Show;
//self.Hide;
except
Application.MessageBox('系统出错!!!', '失败信息', MB_OK);
ModalResult := mrCancel;
exit;
end;
end;
exit;
end
else
begin
iLoginNum := iLoginNum + 1;
Application.MessageBox('登录失败!!!', '失败信息', MB_OK);
with adoquery1 do
begin
Close;
Sql.Clear;
Sql.Add('Insert Into Login(CZYGH, CZNRH, CZSJ)');
Sql.Add(' Values ( :a, :b, :c)');
Parameters.ParamValues['a']:= eGH.Text;
Parameters.ParamValues['b']:= 2;
SP.Prepared:=true;
try
SP.ExecProc;
Parameters.ParamValues['c']:=SP.Parameters.ParamValues['@RetDateTime']; //Get DateTime from Server;
ExecSql;
except
Application.MessageBox('系统出错!!!', '失败信息', MB_OK);
ModalResult := mrCancel;
exit;
end;
end;
if iLoginNum >= 3 then
begin
ModalResult := mrCancel;
exit;
end;
eGH.Text := '';
eYHM.Text := '';
ePWD.Text := '';
eGH.SetFocus ;
ModalResult := mrNone;
end;
end;
改一改吧,对你以后有帮助
代码实现postren的方法不错,不过返回错误应该有两种.一种是密码错误,另一种是用户不存在.
如果更完整的考虑,还加上异常.
上面界面的那个按钮和输入框用DELPHI怎么做出来啊