我用的是c/s开发的。 midas com。我的登录界面是可以正常登录和取消的。但是当我在用户名和密码皆为空的时候点击登录就报这个错误:不能比较或排序text、ntext和image数据类型,除非使用is null 或 like运算。但我的用户名和密码都是char刑的呀。那位高手给指点一下。代码如下:
procedure TfrmLogin.btnOkClick(Sender: TObject);
var
username, password: string;
begin
//if()
username := edtusername.Text;
password := edtpassword.Text;
try dmClient.cdsLogin.Active:=False;
{dmclient.cdsLogin.CommandText:='select * from systemusers'
+'where username=:username and password=:password';}
//向应用服务器传递参数值,以便进行查询
dmClient.cdsLogin.FetchParams;
dmclient.cdsLogin.Params.ParamByName('username').Value:=username;
dmclient.cdsLogin.Params.ParamByName('password').Value:=password;
dmclient.cdsLogin.Open;
//查到唯一用户
if dmclient.cdsLogin.RecordCount=1 then
begin
//取得用户权限
formMain.authorization:= dmclient.cdsLogin.fieldbyname('authorization').Value;
flag:= true;
close;
end
else
begin
flag:=false;
messagedlg('用户验证失败', mterror, [mbok], 0);
exit;
end;
except
on e:exception do
begin
messagedlg('错误:' + e.Message, mterror, [mbok], 0);
exit;
end; end;end;
procedure TfrmLogin.btnOkClick(Sender: TObject);
var
username, password: string;
begin
//if()
username := edtusername.Text;
password := edtpassword.Text;
try dmClient.cdsLogin.Active:=False;
{dmclient.cdsLogin.CommandText:='select * from systemusers'
+'where username=:username and password=:password';}
//向应用服务器传递参数值,以便进行查询
dmClient.cdsLogin.FetchParams;
dmclient.cdsLogin.Params.ParamByName('username').Value:=username;
dmclient.cdsLogin.Params.ParamByName('password').Value:=password;
dmclient.cdsLogin.Open;
//查到唯一用户
if dmclient.cdsLogin.RecordCount=1 then
begin
//取得用户权限
formMain.authorization:= dmclient.cdsLogin.fieldbyname('authorization').Value;
flag:= true;
close;
end
else
begin
flag:=false;
messagedlg('用户验证失败', mterror, [mbok], 0);
exit;
end;
except
on e:exception do
begin
messagedlg('错误:' + e.Message, mterror, [mbok], 0);
exit;
end; end;end;
不要用'where username=:username',用'where username like :username'
procedure TFormmain.Action7Execute(Sender: TObject);
begin
frmLogin:=TfrmLogin.create(Self);
frmLogin.ShowModal; end;