我用的 access数据库  一运行 就提示 could not convert variant of type (NULL) into type (String) ,请问是怎么回事?
         adoquery1.Close;
            adoquery1.sql.Clear;
            adoquery1.sql.Add('select zt,kc,RQ from ceshi where cp="cnc" order by kc');
            adoquery1.open;           with adoquery2 do
            begin
                close;
                sql.Clear;
                sql.Add('select xm,xb,nl from ceshi2 where kc=:kc and  rq between :rq and :dqrq');
                Parameters.ParamByName('kc').Value:=adoquery1['kc'];
                Parameters.ParamByName('rq').Value:=adoquery1['RQ'];
                Parameters.ParamByName('dqrq').Value:=formatdatetime('',now);
                open;
end;                    
                              stringgrid1.cells[0,2]:=adoquery2['xm'];
                              stringgrid1.cells[1,3]:=adoquery2['xb'];
                                                                        

解决方案 »

  1.   

    Parameters.ParamByName('dqrq').Value:=formatdatetime('',now);
    空字段不能转换成string
      

  2.   

    这个 我改了 不行, 出错提示 在这  stringgrid1.cells[0,2]:=adoquery2['xm'];
    是不是不能获取 adoquery2['xm']里面的值;
      

  3.   

     Parameters.ParamByName('dqrq').Value:=formatdatetime('yyyy-mm-dd hh:nn:ss',now);
      open;
      

  4.   

    adoquery2['xm']沒有內容時是null改用:adoquery2.fieldbyname('xm').asstring
    沒有內容時是''
      

  5.   

    stringgrid1.cells[0,2]:=null 
    是错误的,所以要让它变成
    stringgrid1.cells[0,2]:=''
      

  6.   

    我 改用 adoquery2.fieldbyname('xm').asstring不出现错误了 可是 值显示不出来  这是为什么?我的  表里面有值 而且没有空值!
      

  7.   


    那是条件不符,查询不到数据
    自己要学会调试,可以用showmessage();看看有没有值;改为这样试试:Parameters.ParamByName('kc').Value:=adoquery1.fieldbyname('kc').asstring;
    Parameters.ParamByName('rq').Value:=formatdatetime('yyyy-mm-dd',adoquery1.fieldbyname('RQ').asDateTime);
    Parameters.ParamByName('dqrq').Value:=formatdatetime('yyyy-mm-dd',now);