为什么只更新一条记录?

topawei 2002-11-08 11:58:28
我是一位超级菜鸟,还请各位大哥帮忙!
就是下面的代码:

int li_row,i,li_year,ldec_voucher_id,ldec_voucher_item_id
string ls_print_flag,ls_temp_date
date ld_current_date,ld_date
datetime ldt_current_date

li_row=dw_select_printed.rowcount()

select system_date into :ldt_current_date from routinestatus;
ld_current_date=date(ldt_current_date)

for i = 1 to li_row
ls_print_flag=dw_select_printed.getitemstring(i,"print_flag")
if ls_print_flag="1" then
ldec_voucher_id=dw_select_printed.getitemdecimal(i,"voucher_id")
ldec_voucher_item_id=dw_select_printed.getitemdecimal(i,"voucher_item_id")
ld_date=date(dw_select_printed.getitemdatetime(i,"date"))

EXECUTE IMMEDIATE "BEGIN TRANSACTION" USING SQLCA;
IF SQLCA.SQLCode<0 THEN
MessageBox("错误","数据库事务启动错误!")
END IF


if ld_date>date(string(year(ld_current_date))+"-07-01") then
update persondetailaccount
set print_flag="1"
where account=:gs_unitaccount and
person_account=:gs_personaccount and
voucher_id=:ldec_voucher_id and
voucher_item_id=:ldec_voucher_item_id;
end if

if ld_date<date(string(year(ld_current_date))+"-07-01") then
update historyhouse..prioryear_persondetailaccount
set print_flag="1"
where account=:gs_unitaccount and
person_account=:gs_personaccount and
voucher_id=:ldec_voucher_id and
voucher_item_id=:ldec_voucher_item_id;
end if

IF SQLCA.SQLCode<0 THEN
EXECUTE IMMEDIATE "ROLLBACK TRANSACTION" USING SQLCA;
MessageBox("错误","数据库数据修改错误!")
END IF

EXECUTE IMMEDIATE "COMMIT TRANSACTION" USING SQLCA;

end if

NEXT
close(parent)
...全文
25 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
topawei 2002-11-11
  • 打赏
  • 举报
回复
哦,单独分成几个部分可以执行成功,但是组合在一起就不行了
topawei 2002-11-11
  • 打赏
  • 举报
回复
上面两位的方法我都试过了,还是没有答案!
chengkai 2002-11-08
  • 打赏
  • 举报
回复
完全可以由pb的sqlca事务对象来控制数据的提交和回滚
更改为

int li_row,i,li_year,ldec_voucher_id,ldec_voucher_item_id
string ls_print_flag,ls_temp_date
date ld_current_date,ld_date
datetime ldt_current_date

li_row=dw_select_printed.rowcount()

select system_date into :ldt_current_date from routinestatus;
ld_current_date=date(ldt_current_date)
sqlca.autocommit=false
for i = 1 to li_row
if dw_select_printed.getitemstring(i,"print_flag")="1" then
ldec_voucher_id=dw_select_printed.getitemdecimal(i,"voucher_id")
ldec_voucher_item_id=dw_select_printed.getitemdecimal(i,"voucher_item_id")
ld_date=date(dw_select_printed.getitemdatetime(i,"date"))
if ld_date>date(string(year(ld_current_date))+"-07-01") then
update persondetailaccount
set print_flag="1"
where account=:gs_unitaccount and
person_account=:gs_personaccount and
voucher_id=:ldec_voucher_id and
voucher_item_id=:ldec_voucher_item_id;
end if

if ld_date<date(string(year(ld_current_date))+"-07-01") then
update historyhouse..prioryear_persondetailaccount
set print_flag="1"
where account=:gs_unitaccount and
person_account=:gs_personaccount and
voucher_id=:ldec_voucher_id and
voucher_item_id=:ldec_voucher_item_id;
end if
if sqlca.sqlcode<>0 then
rollback;
else
commit;
end if
end if
next
close(parent)
hanyongbinlq 2002-11-08
  • 打赏
  • 举报
回复
if sqlca.sqlcode<>0 then
rollback;
else
commit;
end if
将上面的语句放到循环外面
linyuze 2002-11-08
  • 打赏
  • 举报
回复
我觉的写的也没什么问题!如果跟踪还没问题的化!
把代码拆成4部门,逐个运行!在试试,应该会发现问题!
topawei 2002-11-08
  • 打赏
  • 举报
回复
这里的高手不是很多吗?拜托大家帮帮忙!很急~
lxb_lxb_2002 2002-11-08
  • 打赏
  • 举报
回复
欢迎大家到我那里说两句
topawei 2002-11-08
  • 打赏
  • 举报
回复
没人帮忙吗?
topawei 2002-11-08
  • 打赏
  • 举报
回复
您能回复我就很感谢了!
我跟了好几次,确信循环无误,要取的值也随着循环变化,update也执行了几次,就是到后台一看还是就更新了一条记录!
chengkai 2002-11-08
  • 打赏
  • 举报
回复
不好意思,刚才出去办事了,才回来,
用debug跟踪以下看一看
topawei 2002-11-08
  • 打赏
  • 举报
回复
谢谢您的回复!但是从结果上来说您的方法和我的基本上是一样的,我现在要解决的问题是在循环的过程中要更新几条选中的记录,但不知为什么只能更新1条?

740

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 脚本语言
社区管理员
  • 脚本语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧