sqlca.sqlcode返回值为-1,提示更新失败。??但表却更新成功为何?

jxskyinfoi 2002-03-13 04:40:14
我的代码是这样的:数据库用MS SQL 2000
sqlca.autocommit=true
insert into ......
commit sqlca;
if sqlca.sqlcode<>0 then
messagebox("","更新失败!")
else
messagebox("",更新成功!")
end if
结果:sqlca.sqlcode返回值为-1,提示更新失败。??但表却更新成功为何?但表确实更新了。
...全文
298 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
feixuepiaopiao 2002-03-13
  • 打赏
  • 举报
回复
SQLCA 已经提交就不需要再连接
而且不能用COMMIT SQLCA来对SQLCA。SQLCODE 进行判断
zhanwei 2002-03-13
  • 打赏
  • 举报
回复
当:sqlca.autocommit=true 时
PowerBuilder issues SQL statements outside the scope of a transaction. The statements are not part of a logical unit of work (LUW). If the SQL statement is successful, the DBMS updates the database immediately as if a COMMIT statement had been issued?
当:sqlca.autocommit=false 时
(Default) PowerBuilder issues SQL statements inside the scope of a transaction. PowerBuilder issues a BEGIN TRANSACTION statement at the start of the connection and issues another BEGIN TRANSACTION statement after each COMMIT or ROLLBACK statement is issued
因此:
sqlca.autocommit=true
insert into ......

//commit sqlca; 去掉即可

if sqlca.sqlcode<>0 then
messagebox("","更新失败!")
else
messagebox("",更新成功!")
end if
sincerity 2002-03-13
  • 打赏
  • 举报
回复
为什么要设成 AutoCommit?
这里的 SQLCA.SQLCode 取得的并不是 Insert 语句的执行结果。
insert into ......
if sqlca.sqlcode<>0 then
messagebox("","更新失败!")
else
messagebox("",更新成功!")
commit sqlca;
end if
Leehunter 2002-03-13
  • 打赏
  • 举报
回复
首先设置
sqlca.autocommit=false
然后
insert into ....
if sqlca.sqlcode=0 then
commit;
else
rollback;
end if
你的返回值返回了commit的执行状态。由于autocommit设置为true了,可能会=-1。

396

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 非技术版
社区管理员
  • 非技术版社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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