如何检查将上传和回滚事务的错误数据? [英] How to check error data that will be upload and roll back transaction?

查看:45
本文介绍了如何检查将上传和回滚事务的错误数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮导入将csv文件数据上传到sql server。如果有一行无法提交,我如何检查错误?它会抛出异常。但是如何知道哪些行数据有错误?然后我想回滚交易。



我使用这段代码将数据上传到sql server。



Hi, I have a button import to upload csv file data into sql server.How can I check the error if there are one of the row cannot commit? It will throw the exception. But how to know which row data have the error? Then I want roll back the transaction.

I am using this code to upload data into sql server.

private UCA.Common.DataControl.DBUtility dbu = UCA.Common.DataControl.DBOperatorFactory.GetDBOperator(System.Configuration.ConfigurationManager.AppSettings["DBType"].ToString());










string[] cols3 = { "Creator", "Creation_Time", "Date" };
string[] vals3 = { this.UserID, DateTime.Now.ToString, DateTime.Now.ToString}
dbu.insertRow("Asset_Flow_History", cols3, vals3); 

推荐答案

我认为你可以在单个交易中提交所有行,如果出现问题你可以回滚交易,如果不是你可以提交你的答案



SqlTransaction transaction = sqlConnection.BeginTransaction(IsolationLevel.ReadCommitted); //选择你的隔离级别



然后将此事务添加到您的SqlCommand



希望这可以帮助您
i think you can submit all rows in single transaction if something goes wrong you can rollback the transaction if not you can commit your answer

SqlTransaction transaction = sqlConnection.BeginTransaction(IsolationLevel.ReadCommitted);//choose your isolationLevel

then add this transaction to your SqlCommand

hope this help you


这篇关于如何检查将上传和回滚事务的错误数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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