procedure TForm2.BitBtn1Click(Sender: TObject);
var
sql,namestr,passwdstr,passwd:string;
begin
namestr:=combobox1.Text;//接收用户名
passwdstr:=edit1.Text;//接收密码
sql:='select password from bursar_syry where name='''+namestr+'''';
adoquery1.SQL.Clear;
adoquery1.SQL.Add(sql);
adoquery1.Open;
passwd:=dbtext1.Caption;//保存从数据库中取得的密码
if length(passwdstr)=0 then showmessage('请输入密码')
else
begin
if length(passwd)=0 then showmessage('用户不存在')
else
begin
if ansisametext(passwdstr,passwd) then
form1.show
else
showmessage('密码错误');
end;
end;
combobox1.Text:='';
edit1.Text:='';
dbtext1.Caption:='';
end;
我的问题是输入正确的密码之后,显示的是“密码错误”,用‘=’比较passwd和passwdstr也是错,请告诉我如何解决这种从数据库中取得密码和用户输入的密码的比较问题,数据库中password是char(10)
var
sql,namestr,passwdstr,passwd:string;
begin
namestr:=combobox1.Text;//接收用户名
passwdstr:=edit1.Text;//接收密码
sql:='select password from bursar_syry where name='''+namestr+'''';
adoquery1.SQL.Clear;
adoquery1.SQL.Add(sql);
adoquery1.Open;
passwd:=dbtext1.Caption;//保存从数据库中取得的密码
if length(passwdstr)=0 then showmessage('请输入密码')
else
begin
if length(passwd)=0 then showmessage('用户不存在')
else
begin
if ansisametext(passwdstr,passwd) then
form1.show
else
showmessage('密码错误');
end;
end;
combobox1.Text:='';
edit1.Text:='';
dbtext1.Caption:='';
end;
我的问题是输入正确的密码之后,显示的是“密码错误”,用‘=’比较passwd和passwdstr也是错,请告诉我如何解决这种从数据库中取得密码和用户输入的密码的比较问题,数据库中password是char(10)
var LogQuery:TADOQuery;
begin
LogQuery:=TADOQuery.Create(NIL);
LogQuery.Connection:=DataM.ADOConnection; with LogQuery do
begin
close;
sql.Clear;
sql.Add('select 用户名 from 用户表 where 用户名='''+trim(combobox1.Text)+'''');
try
open;
if recordcount<=0 then
begin
showmessage('用户名错误!');
exit;
end
else
zbr:=trim(fields[0].asstring);
except
showmessage('数据打开出错!');
end;
end; with LogQuery do
begin
close;
sql.Clear;
sql.Add('select 密码 from 用户表 where 用户名='''+trim(combobox1.Text)+'''');
try
open;
if trim(fields[0].asstring)=edit1.Text then
begin
operator:=trim(combobox1.Text);
LogForm.Close;
end
else
begin
showmessage('密码错误!');
edit1.SetFocus;
end; except
showmessage('数据打开出错!');
end;
end;
LogQuery.Free;end;
二楼的有道理,用VERCHAR,
或者自己编写代码去掉空格.
passwdstr:=edit1.Text;//接收密码
改为:
namestr:=trim(combobox1.Text);
passwdstr:=trim(edit1.Text;
试试!