使用query进行update和post操作时报dataset not in edit or insert 错误或者modify a readonly data

  • 主题发起人 主题发起人 小皮卡
  • 开始时间 开始时间

小皮卡

Unregistered / Unconfirmed
GUEST, unregistred user!
使用query进行update和post操作时报dataset not in edit or insert 错误或者modify a readonly dataset错误(30分)<br />使用query进行update和post操作时报dataset not in edit or insert 错误
或者modify a readonly dataset错误。我已经把相应的query设置成requestlive:=false
以及dbgrid设置成readonly:=false;请指点。非常感谢!

 
query1.edit
 
同意楼上说法
发生这种错误应该是数据集处于浏览状态,将其修改为编辑状态或插入状态就行了
可以这样:
if query1.state = dsbrowse then
query1.edit; 或 query1.append;
 
requestlive:=true
 
排序过的数据就不能编辑了
 
楼主是不是故意把代码反过来写啊
 
我把canmodify:=true时不运行该行,使用query1..edit也没有作用
 
我也经常出现此种问题,后来我一生气完全改用SQL语句直接写,如,UPDATE,INSERT,
DELETE等,应该不会有什么问题了吧!!!!!
 
加一条:
query.RequestLive:=true;
 
用Sql写,其性能和效率都比较优秀,建议用AdoQuery或一AdoStoredProc.
 
把代碼貼出來就知道了﹗﹗
 
是不是改成调用存储过程呀。因为就一条更新语句,就是把浏览过的数据进行状态更改。
你看看还有其他办法吗?
 
procedure TKHSP.Button1Click(Sender: TObject);
var i:integer;
begin
query2.Close;
query2.sql.clear;
query2.SQL.add('select * from kh_bmdw where Dwmc=:dwmc');
query2.Params[0].asstring:=dblookupcombobox1.Text ;
query2.Prepare ;
query2.open;
dwdm:=query2.fieldbyname('Dwdm').asstring;
query1.Close;
query1.sql.clear;
dbgrid1.Columns.Clear;
if khfs='1' //根据KHFS判断扣分表类型
then
begin
query1.sql.add('select a.fxnr,b.fz,b.sl from kh_bmfx a,kh_ydkfb b where b.bkhdw=:bkhdw and b.yd=:yd and a.tablecode=b.tablecode and a.dxbm=b.dxbm and a.xxbm=b.xxbm and a.fxbm=b.fxbm');
UpdateSQL1.ModifySQL.Clear;
UpdateSQL1.ModifySQL.append('update kh_ydkfb set fz=:fz,sl=:sl where fz=:OLD_fz and sl=:OLD_sl');
UpdateSQL1.InsertSQL.Clear;
UpdateSQL1.InsertSQL.append('insert into kh_ydkfb(fz,sl) values(,:fz,:sl)');
UpdateSQL1.DeleteSQL.Clear;
UpdateSQL1.DeleteSQL.append('delete from kh_ydkfb where fz=:OLD_fz and sl=:OLD_sl');
end

else if khfs='2'
then
begin
query1.sql.add('select a.fxnr,b.fz,b.sl from kh_bmfx a,kh_jdkfb b where b.bkhdw=:bkhdw and b.jd=:jd and a.tablecode=b.tablecode and a.dxbm=b.dxbm and a.xxbm=b.xxbm and a.fxbm=b.fxbm');
UpdateSQL1.ModifySQL.Clear;
UpdateSQL1.ModifySQL.append('update kh_jdkfb set fz=:fz,sl=:sl where fz=:OLD_fz and sl=:OLD_sl');
UpdateSQL1.InsertSQL.Clear;
UpdateSQL1.InsertSQL.append('insert into kh_jdkfb(fz,sl) values(,:fz,:sl)');
UpdateSQL1.DeleteSQL.Clear;
UpdateSQL1.DeleteSQL.append('delete from kh_jdkfb where fz=:OLD_fz and sl=:OLD_sl');
end
else
begin
query1.sql.add('select a.fxnr,b.fz,b.sl from kh_bmfx a,kh_ndkfb b where b.bkhdw=:bkhdw and b.nd=:nd and a.tablecode=b.tablecode and a.dxbm=b.dxbm and a.xxbm=b.xxbm and a.fxbm=b.fxbm');
UpdateSQL1.ModifySQL.Clear;
UpdateSQL1.ModifySQL.append('update kh_ndkfb set fz=:fz,sl=:sl where fz=:OLD_fz and sl=:OLD_sl');
UpdateSQL1.InsertSQL.Clear;
UpdateSQL1.InsertSQL.append('insert into kh_ndkfb(fz,sl) values(,:fz,:sl)');
UpdateSQL1.DeleteSQL.Clear;
UpdateSQL1.DeleteSQL.append('delete from kh_ndkfb where fz=:OLD_fz and sl=:OLD_sl');
end;
query1.Params[0].asstring:=dwdm;
if khfs='3' then query1.Params[1].asstring:=ye.Text
else query1.Params[1].asstring:=ye.Text+yuejd.Text;
query1.prepare;
query1.Open;
dbgrid1.Columns[0].Title.Caption:='考核分项内容';
dbgrid1.columns[0].title.Font:=dbgrid1.font;
dbgrid1.Columns[1].Title.Caption:='考核扣分';
dbgrid1.columns[1].title.Font:=dbgrid1.font;
dbgrid1.Columns[2].Title.Caption:='扣分次数';
dbgrid1.columns[2].title.Font:=dbgrid1.font;

dbgrid1.columns[0].Width:=500;
dbgrid1.columns[1].Width:=100;
dbgrid1.columns[2].Width:=100;
dbgrid1.columns[0].ReadOnly:=true;
dbgrid1.columns[1].ReadOnly:=true;
dbgrid1.columns[2].ReadOnly:=true;
end;
procedure TKHSP.FormClose(Sender: TObject; var Action: TCloseAction);
begin
query1.Close;
query1.SQL.clear;
end;

procedure TKHSP.BitBtn1Click(Sender: TObject);
begin
KHSP.FREE;
end;

procedure TKHSP.DBGrid1DblClick(Sender: TObject);
begin
SPXG:=TSPXG.Create(self);
SPXG.Visible:=true;
SPXG.label1.Caption:='';
SPXG.spinedit2.Visible:=false;
SPXG.spinedit2.Value:=1;
SPXG.bitbtn1.Enabled:=false;
SPXG.label1.Caption :=query1.fieldbyname('fxnr').asstring;
SPXG.spinedit1.value:=query1.fieldbyname('fz').asinteger;
SPXG.SpinEdit2.Visible:=true;
SPXG.SpinEdit2.Value:=query1.fieldbyname('sl').asinteger;
SPXG.dwmc.Visible:=true;
end;

procedure TKHSP.BitBtn2Click(Sender: TObject);
begin
dbgrid1.columns[0].ReadOnly:=false;
dbgrid1.columns[1].ReadOnly:=false;
dbgrid1.columns[2].ReadOnly:=false;
{if query3.canmodify then
begin
query1.Close;
query3.sql.clear;
if khfs='1' //根据KHFS取扣分表
then query3.sql.add('update kh_ydkfb set zt="1" where bkhdw=:bkhdw and yd=:yd')
else if khfs='2'
then query3.sql.add('update kh_jdkfb set zt="1" where bkhdw=:bkhdw and jd=:jd')
else query3.sql.add('update kh_ndkfb set zt="1" where bkhdw=:bkhdw and nd=:nd');
query3.Params[0].asstring:=dwdm;
if khfs='3' then query3.Params[1].asstring:=ye.Text
else query3.Params[1].asstring:=ye.Text+yuejd.Text;
query3.prepare;
query3.Execsql;
query3.Close;
end
else
begin
beep;
Application.MessageBox('审批数据未存入考核扣分表!','目标管理考核系统--错误信息',MB_OK + MB_ICONERROR);
end;
end; }

log.Database2.StartTransaction;
log.Database2.TransIsolation:=tiDirtyRead;
query3.Close;
query3.sql.clear;
if khfs='1' //根据KHFS判断扣分表类型
then
begin
query3.sql.add('update kh_ydkfb set zt="1" where bkhdw=:bkhdw and yd=:yd');
UpdateSQL2.ModifySQL.Clear;
UpdateSQL2.ModifySQL.append('update kh_ydkfb set zt="1" where zt=:OLD_zt');
end
else if khfs='2'
then
begin
query3.sql.add('update kh_jdkfb set zt="1" where bkhdw=:bkhdw and yd=:yd');
UpdateSQL2.ModifySQL.Clear;
UpdateSQL2.ModifySQL.append('update kh_jdkfb set zt="1" where zt=:OLD_zt');
end
else
begin
query3.sql.add('update kh_ndkfb set zt="1" where bkhdw=:bkhdw and yd=:yd');
UpdateSQL2.ModifySQL.Clear;
UpdateSQL2.ModifySQL.append('update kh_ndkfb set zt="1" where zt=:OLD_zt');
end;
query3.Params[0].asstring:=dwdm;
if khfs='3' then query3.Params[1].asstring:=ye.Text
else query3.Params[1].asstring:=ye.Text+yuejd.Text;
query3.prepare;
query3.execsql;


Try
KHSP.query3.ApplyUpdates;
log.Database2.Commit;

except
Begin
beep;
log.Database2.Rollback;
log.Database2.TransIsolation:=tiReadCommitted;
Application.MessageBox('审批数据未存入考核扣分表!','镇江国税目标考核管理系统--错误信息',MB_OK + MB_ICONERROR);
raise;
end;
end;
KHSP.query3.CommitUpdates;
log.Database2.TransIsolation:=tiReadCommitted;
end;
 
procedure TKHSP.Button1Click(Sender: TObject);
var i:integer;
begin
query2.Close;
query2.prepare;
query2.sql.clear;
query2.SQL.add('select * from kh_bmdw where Dwmc=:dwmc');
query2.Params[0].asstring:=dblookupcombobox1.Text ;
query2.UnPrepare ;
query2.EXECSQL;
dwdm:=query2.fieldbyname('Dwdm').asstring;
query1.Close;
.....................................
.......................................

应该先调用PREPARE,然后再释放掉UNPREPARE.应该调用EXECSQL.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
948
import
I
后退
顶部