比如:类型表:
ID,intType
1      1
2      2
3      3
其中我用sql语句查询后,类型不知算不算变了?之后修改就出错?adoquery1.sql.clear
adoquery1.sql.text:='select case when intTYpe=1 then ''类型一'' when intType=2 then ''类型二'' when intType=3 then ''类型三'' as intType1 from 类型表'
adoquery1.open
以上查询,不知道是不是将源字段暂时变为字符串类型了.
我执行下面就出错if not adoquery1.eof then
 begin
 if adoquery1.state in [dsInsert,dsEdit] then
  begin
    adoquery1.fieldbyname('intType1').value=5;
    adoquery1.post;
 end;
end;执行以上语句就会出现:
Field 'intType1' cannot be modified.
不知道是怎么回事?

解决方案 »

  1.   

    intType1是一个虚拟字段,不能修改
      

  2.   

    adoquery1.sql.clear
    adoquery1.sql.text:='select case when intTYpe=1 then ''类型一'' when intType=2 then ''类型二'' when intType=3 then ''类型三'' as intType1 from 类型表'
    adoquery1.open
    --
    adoquery1.sql.clear
    adoquery1.sql.text:='select case when intTYpe=1 then ''类型一'' when intType=2 then ''类型二'' when intType=3 then ''类型三'' end as intType1 from 类型表'
    adoquery1.open
      

  3.   

    不是上面的关系,查询的sql语句在我程序里是正确的,我只是重新输入到上面时少了一个'End',我查询运行正确,就是在添加时错误那如果现在需要修改呢?应该怎么处理?
      

  4.   

    if not adoquery1.eof then
     begin
     if adoquery1.state in [dsInsert,dsEdit] then
      begin
        adoquery1.fieldbyname('intType1').value=5;
        adoquery1.post;
     end;
    end;---------
    if not adoquery1.eof then
     begin
     if adoquery1.state in [dsInsert,dsEdit] then
      begin
        adoquery1.fieldbyname('intType1')).value='5';    adoquery1.post;
     end;
    end;
      

  5.   

    if not adoquery1.eof then
     begin
     if adoquery1.state in [dsInsert,dsEdit] then
      begin
        adoquery1.fieldbyname('intType1')).Asstring='5';
        adoquery1.post;
     end;
    end;
      

  6.   

    'select case when intTYpe=1 then ''类型一'' when intType=2 then ''类型二'' when intType=3 then ''类型三'' as intType1 from 类型表'
    if not adoquery1.eof then
     begin
     if adoquery1.state in [dsInsert,dsEdit] then
      begin
        adoquery1.fieldbyname('intType1').value=5;
        adoquery1.post;
     end;
    end;数据库中根本不存在intType1怎么能保存呢
      

  7.   

    inttype1 在数据库中不存在,则且被转换成字符型了
    你应该把类型做个基础表,做为关联,这才是解决你程序中的方法。
      

  8.   

    'select case when intTYpe=1 then ''类型一'' when intType=2 then ''类型二'' when intType=3 then ''类型三'' as intType from 类型表' 我改成上面了if not adoquery1.eof then 
     begin 
     if adoquery1.state in [dsInsert,dsEdit] then 
      begin 
        adoquery1.fieldbyname('intType').asstring='5'; 
        adoquery1.post; 
     end; 
    end;也不行!
      

  9.   

    'select case when intTYpe=1 then ''类型一'' when intType=2 then ''类型二'' when intType=3 then ''类型三'' as intType,intType as iT from 类型表'  我改成上面了 if not adoquery1.eof then  
     begin  
     if adoquery1.state in [dsInsert,dsEdit] then  
      begin  
        adoquery1.fieldbyname('iT').value=5;  
        adoquery1.post;  
     end;  
    end; 现在可以了,我将显示跟原字段分开显示就可以了。
    不过感觉这样怪怪的
      

  10.   

    1.分清楚虚拟字段与真实字段
    2.在修改时要修改真实字段  With ADOQuery1 do
      begin
        Close;
        Sql.Clear;
        sql.Text:='select IntType,case when intTYpe=1 then ''类型一'' when intType=2 then ''类型二'' when intType=3 then ''类型三''  end as intType1 from Test' ;
        Open;
      end;
      然后再对真实字段IntType进行修改!
      

  11.   


      adoquery1.fieldbyname('intType').asstring:='2';//intType是源或真实字段,intType1为虚拟字段
      adoquery1.post;
      

  12.   

    close;
    sql.Clear;
    sql.Add('select case when intType=1 then ''类型一'' when intType=2 then ''类型二'' when intType=3 then ''类型三'' end  as inttype1 from test ');
    open;
    按照LZ的意思,我一样写了个测试代码,怎么运行老是显示CASE查询表达式语法出错,请各位大老赐教,谢谢!