比如:类型表:
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.
不知道是怎么回事?
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.
不知道是怎么回事?
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
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;
begin
if adoquery1.state in [dsInsert,dsEdit] then
begin
adoquery1.fieldbyname('intType1')).Asstring='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;数据库中根本不存在intType1怎么能保存呢
你应该把类型做个基础表,做为关联,这才是解决你程序中的方法。
begin
if adoquery1.state in [dsInsert,dsEdit] then
begin
adoquery1.fieldbyname('intType').asstring='5';
adoquery1.post;
end;
end;也不行!
begin
if adoquery1.state in [dsInsert,dsEdit] then
begin
adoquery1.fieldbyname('iT').value=5;
adoquery1.post;
end;
end; 现在可以了,我将显示跟原字段分开显示就可以了。
不过感觉这样怪怪的
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进行修改!
adoquery1.fieldbyname('intType').asstring:='2';//intType是源或真实字段,intType1为虚拟字段
adoquery1.post;
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查询表达式语法出错,请各位大老赐教,谢谢!