要求:用delphi7设计了一个登陆界面,数据库是oracle数据库,在oracle的system权限下有一张userinfo的表,表中有两个字段 username 和password ,现在我想通过登陆界面输入用户名和密码,点确定的时候 系统判断是不是userinfo表中的username和password 是得话就跳到下一个窗口,不是的话,就提示错误.求高写个简单点的案例.菜鸟求教.谢谢!
调试欢乐多
不想装oracle客户端的话数据库控件用odac
if Trim(User.Text)<>'' then
begin
with adologin do
begin
Close;
SQL.Text:='select * from userinfo where username='''+Trim(user.Text)+''' and password='''+pw.Text+'''';
Open;
if not Eof then
begin
Form1.show;
self.Hide;
end
else
begin
MessageBox(Handle,'用户名或密码错误!','提示',MB_OK);
exit;
end;
end;
with adoquery1 do
begin
adoquery1.Close;
ADOQuery1.SQL.clear;
ADOQuery1.SQL.Add('select * from yz_userinfo Where SYHMC='''+trim(combobox1.Text)+''' And SPWD='''+Trim(edit1.text)+'''');
parameters[0].Value:=combobox1.Text;
parameters[1].Value:=edit1.Text;
open;
end;
if adoquery1.RecordCount<>0 then
showmessage('登录成功!')
else showmessage('用户名或密码错误');end;
end.
//以上是我自己写的.编译可以过.为什么总是出错呢.请教大人.
所以去掉:
parameters[0].Value:=combobox1.Text;
parameters[1].Value:=edit1.Text;或者改这句:
ADOQuery1.SQL.Add('select * from yz_userinfo Where SYHMC=:A And SPWD=:B');
我按你的写法写成如下:
procedure TForm1.Button3Click(Sender: TObject);begin
with adoquery1 do
begin
adoquery1.Close;
ADOQuery1.SQL.clear;
ADOQuery1.SQL.Add('select * from yz_userinfo Where SYHMC=:A And SPWD=:B');
open;
end;
if adoquery1.RecordCount<>0 then
showmessage('登录成功!')
else showmessage('用户名或密码错误');end;
end.
还是不对.不过奇怪.怎么总是提示一个错误:
project project1.exe raised exception class E0leException with message 'ORA-01017'
下面这段代码不是很清晰。
注:不要加这个:
parameters[0].Value:=combobox1.Text;
parameters[1].Value:=edit1.Text;if Trim(User.Text)<>'' then
begin
with adologin do
begin
Close;
SQL.Text:='select * from userinfo where username='''+Trim(user.Text)+''' and password='''+pw.Text+'''';
Open;
if not Eof then
begin
Form1.show;
self.Hide;
end
else
begin
MessageBox(Handle,'用户名或密码错误!','提示',MB_OK);
exit;
end;
end;
用userinfo中的用户名和密码肯定不能登录Oracle的。
ORA-01017就是用户/密码错误的提示。