如何检查事务是否更新 [英] How to check whether transaction updated or not

查看:71
本文介绍了如何检查事务是否更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查更新查询是否更新了记录。我已经使用cmd.ExecuteNonQuery()更新记录

How to check whether a update query updated the record or not. i have used cmd.ExecuteNonQuery() to update record

推荐答案

对于这种情况我的方法是设置try和catch块如果Transaction成功使用Select 1并在前端得到1个数据集中的输出并检查数据集元素是真还是假,在此基础上你可以检查交易是否完成
For such cases My method is set try and catch block if Transaction is successful use Select 1 and in front end get output in 1 dataset and check dataset element is true or false on that basis you can check transaction completed or not


在商店程序中



In Store Procedure

BEGIN TRY 
BEGIN TARN
your code
COMMIT TRAN
Select 1 As 'Sucess'
END TRY
BEGIN CATCH
ROLLBACK TRAN
SELECT 0 AS 'Error'
END CATCH





C#代码



你可以参考这个链接



http: //stackoverflow.com/questions/1249091/how-to-get-datatable-as-a-result-of-stored-procedure [ ^ ]


这篇关于如何检查事务是否更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆