加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi 中出现dataset not in edit or insert mode的问题

发布时间:2020-12-15 09:48:12 所属栏目:大数据 来源:网络整理
导读:self.ADOQuery2.Edit; self.ADOQuery2.First; while not self.ADOQuery2.Eof do begin self.ADOQuery2.FieldByName(‘单价‘).Value:=roundto(self.ADOQuery2.FieldByName(‘单价‘).Value,-2); self.ADOQuery2.Next; end; self.ADOQuery2.Post; 这是显示在
self.ADOQuery2.Edit;
self.ADOQuery2.First;
while not self.ADOQuery2.Eof do
begin
self.ADOQuery2.FieldByName(‘单价‘).Value:=roundto(self.ADOQuery2.FieldByName(‘单价‘).Value,-2);
self.ADOQuery2.Next;
end;
self.ADOQuery2.Post;
这是显示在一个DBGrid里面
我是想把单价保留2位小数,
但是老出现这个问题,显示出错的self.ADOQuery2.Next句
我在网上也找了,都说是没进入edit状态,
但是我明明有edit,问题出在哪里,请帮帮忙
当你使用First或Next时ADOQuery2会自动Post,ADOQuery2处于dsBrowse状态(数据集已打开,可以浏览数据,但是不能进行修改)
所以你必须在赋值语句前使用Edit,我帮你修改程序如下:

self.ADOQuery2.First;
while not self.ADOQuery2.Eof do
begin
self.ADOQuery2.Edit;
self.ADOQuery2.FieldByName(‘单价‘).Value:=roundto(self.ADOQuery2.FieldByName(‘单价‘).Value,-2);
self.ADOQuery2.Post;
self.ADOQuery2.Next;
end;
//self.ADOQuery2.Edit; X
self.ADOQuery2.First;
while not self.ADOQuery2.Eof do
begin
ADOQuery2.Edit; ///
self.ADOQuery2.FieldByName(‘单价‘).Value:=roundto(self.ADOQuery2.FieldByName(‘单价‘).Value,-2);
ADOQuery2.Post; ///self.ADOQuery2.Next;end;//self.ADOQuery2.Post; XEdit针对当前游标所在行,你next的时候,游标移动了,这个时候会自动POST

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读