论坛: 编程破解 标题: delphi中有关ado的问题(也很有可能是我的程序有问题:-)) 复制本贴地址    
作者: zhoen889 [zhoen889]    论坛用户   登录
我在用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不行.
在此先多谢谢了.

地主 发表时间: 05-10-03 11:03

回复: 286 [unique]   版主   登录
不能把空串转为字符串。
估计问题出在“if (adotable1.FieldByName('id').value=trim(user_name)) and
          (adotable1.FieldByName('password').value=trim(edit1.text)) then
”上。
是不是id,password,user_name,edit1.text四者中有空的。

B1层 发表时间: 05-10-08 16:24

回复: kangtaowe [tangying]   论坛用户   登录
  if (adotable1.FieldByName('id').value=trim(user_name)) and
          (adotable1.FieldByName('password').value=trim(edit1.text))  有空字符

B2层 发表时间: 05-10-09 11:14

回复: zhoen889 [zhoen889]   论坛用户   登录
按理说,我在前面已经验证过了,不可能为空啊!
对了,昨天晚上我再用的时候,突然又没有那个错误了,也不知道是不是我的window2000系统和office xp有冲突,所以在识别access数据库的时候有问题?

B3层 发表时间: 05-10-09 22:07

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号