关于数据类型的问题:
如:
var
x3,x4:real;
begin
 x3:=null;
 x4:=null;
 adoquery1.InsertRecord([x3,x4]);
end;
这样就报错;而var
x3,x4:real;
begin
 x3:=null;
 x4:=null;
 adoquery1.InsertRecord([null,null]);
end;
就可以。请问如何用变量的形式即adoquery1.InsertRecord([x3,x4])这种形式,把空值包含进来?

解决方案 »

  1.   

    说得比较罗索,其实就是adoquery1.InsertRecord([x3,x4])在x3,x4为空的时候,怎么办。(数据库的字段是double型)如果不给x3,x4赋值,他们就是0,这样插进数据库也就是0了。而我不想在数据库中弄很多0,我宁可他们是空值。但是我给他们赋空值的时候,adoquery1.InsertRecord([x3,x4])又出错,怎么办?
      

  2.   

    if (x3=null) and (x4<>null) then
      adoquery1.InsertRecord([null,x4])
    else
    if (x3<>null) and (x4=null) then
      adoquery1.InsertRecord([x3,null])
    else
    if (x3=null) and (x4=null) then
      adoquery1.InsertRecord([null,null])
    else
      adoquery1.InsertRecord([x3,x4]);
      

  3.   

    改用
    adoquery1.Insert;
    adoquert1.FieldByName('字段').asString := x3;
    adoquert1.FieldByName('字段').asString := x4;
    adoquery1.Post;
      

  4.   

    if (x3=null) and (x4<>null) then
      adoquery1.InsertRecord([null,x4])
    else
    if (x3<>null) and (x4=null) then
      adoquery1.InsertRecord([x3,null])
    else
    if (x3=null) and (x4=null) then
      adoquery1.InsertRecord([null,null])
    else
      adoquery1.InsertRecord([x3,x4]);
    正确
      

  5.   

    adoquery1.Insert;
    adoquert1.FieldByName('字段').asString := x3;
    adoquert1.FieldByName('字段').asString := x3
    adoquery1.Post;
    //x3,x4类型不符啊。楼主定义的是real
      

  6.   

    yalaso(那夜我喝醉了) ( ) 信誉:100  2005-01-19 09:54:00  得分: 0  
     
     
       if (x3=null) and (x4<>null) then
      adoquery1.InsertRecord([null,x4])
    else
    if (x3<>null) and (x4=null) then
      adoquery1.InsertRecord([x3,null])
    else
    if (x3=null) and (x4=null) then
      adoquery1.InsertRecord([null,null])
    else
      adoquery1.InsertRecord([x3,x4]);====================================================你这样就麻烦死了,其实我有10个这样的变量呢,^_^  
     
      

  7.   

    adoquery1.Insert;
    if x3<>null then
    adoquert1.FieldByName('字段').asString := x3;
    if x4<>null then
    adoquert1.FieldByName('字段').asString := x4
    adoquery1.Post;//可以这样啊,如果不为空就插入这个值,为空就不要管它了,也就是null啊