当前位置:主页>仓库管理软件> 列表

请问一个有关ado的问题~

企业管理软件版1楼: 我在用ado控件做练习的时候,在运行程序的时候,老是出现以下问题提示:
project.exe raised exception class EvariantTypeCastError with message''could not covert variant of type(NULL) into type(string)''
翻译过来,是不能转换成合适的类型所致,但是我不知道怎么修改程序(生手:-) )
还有就是程序如果再次点击运行,它能正确运行,并且生成exe后没有上述的错误提示.
我真的不知道这是怎么回事情,高手帮忙啊!
程序代码如下:
procedure Tmodsercet.Button1Click(Sender: TObject);
begin
if edit1.text='''' then //旧密码不能为空
begin
application.MessageBox(''旧密码不能为空,请输入!'',''警告!'',mb_ok);
edit1.SetFocus;
exit;
end;
if (edit2.text='''') or (edit3.text='''') then //新密码也不能为空
begin
application.MessageBox(''新密码不能为空,请输入!'',''警告!'',mb_ok);
edit2.SetFocus;
exit;
end;
if edit2.text<> edit3.text then
begin
application.MessageBox(''两次输入新密码不一致!'',''警告!'',mb_ok);
edit2.Clear ;
edit3.Clear ;
edit2.SetFocus ;
exit;
end;
adotable1.Active:=true; //打开数据
adotable1.First;
while not adotable1.Eof do
begin
//如果条件匹配,则修改密码,并给出信息
if (adotable1.FieldByName(''id'').value=trim(user_name)) and
(adotable1.FieldByName(''password'').value=trim(edit1.text)) then
begin
adotable1.Edit;
adotable1.FieldByName(''password'').AsString:=edit2.Text;
adotable1.Post;
application.MessageBox(''修改密码成功!'',''信息!'',mb_ok);
edit1.Clear;
edit2.Clear;
edit3.Clear;
exit;
end
else
adotable1.Next;
end;
if adotable1.Eof then //如果旧密码输入错误,则需要重新输入密码
begin
application.MessageBox(''旧密码输入不正确!'',''警告!'',mb_ok);
edit1.Clear;
edit2.Clear;
edit3.Clear;
edit1.SetFocus;
exit;
end;
end;
对了,我有一个朋友说是我装的delphi7.0不行.
在此先多谢谢了.

2楼: adotable1.FieldByName(''password'').AsString := edit2.Text
改成
adotable1.FieldByName(''password'').value := edit2.Text 如工程档案管理软件

3楼: 你的程序最好不要这样写,速度慢,还容易出错,
改成这样的吧:
procedure Tmodsercet.Button1Click(Sender: TObject);
begin
if edit1.text='''' or (edit2.text='''') then //新旧密码不能为空
begin
application.MessageBox(''密码不能为空,请输入!'',''警告!'',mb_ok);
edit2.SetFocus;
exit;
end;
if edit2.text<> edit3.text then
begin
application.MessageBox(''两次输入新密码不一致!'',''警告!'',mb_ok);
edit2.Clear ;
edit3.Clear ;
edit2.SetFocus ;
exit;
end;
adotable1.Active:=true; //打开数据
if AdoTable1.Locate(''ID,PassWord'',VarArrayOf([UserName,Edit1.Text]),[]) then


begin
adotable1.Edit;
adotable1.FieldByName(''password'').AsString:=edit2.Text;
adotable1.Post;
application.MessageBox(''修改密码成功!'',''信息!'',mb_ok);
edit1.Clear;
edit2.Clear;
edit3.Clear;
exit;
end
else
begin
application.MessageBox(''旧密码输入不正确!'',''警告!'',mb_ok);
edit1.Clear;
edit2.Clear;
edit3.Clear;
edit1.SetFocus;
exit;
end;

4楼: 错误的原因可能是你用了adotable1.FieldByName(''password'').AsString :=edit2.Text;
如果edit2.text 为空的话就有问题了

5楼: (adotable1.FieldByName(''password'').value=trim(edit1.text))这句吧,改成
(adotable1.FieldByName(''password'').value=VarToStr(trim(edit1.text)))

6楼: 检查一下你的数据库,你的有些字段是否设置为不能为空了,不用限制的字段将其改过来,然后用上面的那位shine007大哥的程序就OK了

企业管理软件版7楼: 多谢谢各位了.[:)][:)]

8楼: 楼3朋友AdoTable1.Locate(''ID,PassWord'',VarArrayOf([UserName,Edit1.Text]),[])


其中id和password是用分号格开的,不是逗号

9楼: 我用以上的各种方法都试验了,结果还是提示那个错误,到底怎么回事情?