我都神经了,都不知道问题出在哪里了???????
我就是想做一个添加的功能。这次我数据库里的字段类型都标出来 朋友们帮我看看啊 ,谢了!!!!
var
   bh:integer;
begin
    adotable1.Active:=true;
    bh:=adotable1.RecordCount;
    adotable1.Insert;
    adotable1.FieldByName('JLBH').AsInteger:=(bh+1);   //int型
    adotable1.FieldByName('CZY').AsInteger:=347;     // int型    strtoint(dbtext1.Caption);
    adotable1.FieldByName('CLSJ').AsDateTime:=strtodatetime(dbtext2.Caption); //datetime类型
    adotable1.FieldByName('CLLX').AsInteger:=10;   //small int型    //   strtoint(dbtext3.Caption);
    adotable1.FieldByName('HYID').AsInteger:=7949;    //int型  /strtoint(dbtext4.Caption);
    adotable1.FieldByName('HYK_NO').AsString:='10090196600';   //varchar型   dbtext5.Caption;
    adotable1.FieldByName('CLJE').AsCurrency:=0;       //money类型    strtocurr(dbtext6.Caption);
    adotable1.FieldByName('CLJF').AsFloat:=0;    //float类型    strtofloat(dbtext7.Caption);
    adotable1.FieldByName('MSG_ID').AsInteger:=7010;    //int类型   /strtoint(dbtext8.Caption);
    adotable1.FieldByName('CAPTION').AsString:=dbtext9.Caption;  // char
    adotable1.FieldByName('BZ').AsString:=dbtext10.Caption;         //char
    adotable1.Post;
    adotable1.Active:=false;
    adotable1.Refresh;
总是报下面的错误

解决方案 »

  1.   

      adotable1.Active:=false;
      adotable1.Refresh;//ADO关闭后还调用Refresh?,删除这个代码
      

  2.   

    这个报错提示很明显了呀你逐个调试,看看是哪个字段类型不匹配,2,3分钟的事
    估计是:
    adotable1.FieldByName('CLSJ').AsDateTime:=strtodatetime(dbtext2.Caption); //datetime类型
      

  3.   

    无效的variant类型转换,一步步跟下去看看,F7
      

  4.   

    这个数错意思是,数据类型转换错误,当然后面adotable1.Refresh也是错的除了下面这句看到是转换外,其它都是数值,字符。只要不超出范围是沒啥问题的
    adotable1.FieldByName('CLSJ').AsDateTime:=strtodatetime(dbtext2.Caption); //datetime类型先确定一下dbtext2.Caption有值吗?是日期类型吗? 可以改成这样试试:
    adotable1.FieldByName('CLSJ').AsDateTime:=Date;
      

  5.   

    基本就是这句了
    adotable1.FieldByName('CLSJ').AsDateTime:=strtodatetime(dbtext2.Caption); 
    别的赋值没错
      

  6.   

    其实不建议用strtodatetime,因为每台机的区域,日期格式设置可能不一样(有的是2012-01-01,2012/02/15,05-02-2012),日期用datetimepicker之类的组件,就可以避免此类问题。