有两个问题:
1.怎样处理NULL?
我的程序:
txt1.text := adoquery.recordset.fields['字段A'].value ;
但当字段A为 NULL时,提示出错:Invalid variant type conversion
当不为NULL时就无事,请问怎样解决?2.我的程序有时会提示出错:
Application uses a value of the worng type for the current operation
代码和数据都没有改变的喔,请问怎样解决?

解决方案 »

  1.   

    1 . 取值时 :   Select IsNull(FieldName,''1234'') as k from tablename where ... ;   然后 :  FieldByName('k').AsString ... 就可以得到2. 代码可以贴么 ?
      

  2.   

    if VarIsNull(adoquery.recordset.fields['字段A'].value) then
      txt1.text := ''
    else
      txt1.text := adoquery.recordset.fields['字段A'].value ;
      

  3.   

    'Select IsNull(FieldName,''1234'') as k from tablename where ... ' ;
      

  4.   

    adoquery.FieldByName('字段A').Asstring
    这样不可以吗?
      

  5.   

    adoquery.FieldByName('字段A').Asstring
    或者你使用查询语句的时候加个WHERE条件 ,让字段不会空。
      

  6.   

    uses variants;txt1.text := vartostr(adoquery.recordset.fields['字段A'].value);
    两个问题都是一样,把variant类型值赋给变量或控件的某一属性时,有时需要转化才行。