本文介绍了如何使用交易就是这种情况..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 好吧所以我有一个webform和5个FileUpload控件..用户可以从1到5加载任意数量的文件,但如果有任何文件没有上传,那么我想回滚所有内容...... 例如: 如果用户选择了4个文件,如果在第4个时发生了意外情况,那么我想删除或回滚所有之前的3个文件上传.. dboperation dbinsert = new dboperation(); Ok so i have a webform and 5 FileUpload control..a user can upoad any number of files from 1 to 5 but if anyone of the files does not get uploaded then i want to rollback everything... For ex: if user has selected 4 files and if something unexpected occurs at 4th then i want to remove or rollback all the previous 3 file uploads..dboperation dbinsert=new dboperation();if (file1.ContentLength > 0){ ....... .......dbo.insert(bytes, lastid, file2.FileName);} if (file2.ContentLength > 0){ ....... .......dbo.insert(bytes, lastid, file2.FileName);} if (file3.ContentLength > 0){ ....... .......dbo.insert(bytes, lastid, file2.FileName);} //......till file5 dboperation是c#文件中的一个类,dbinsert是一个方法正在执行插入存储过程。 //......till file5dboperation is a class in c# file and dbinsert is a method which is executing an insert stored procedure.推荐答案 using (var Conn = new SqlConnection(_ConnectionString)){ SqlTransaction trans = null; try { Conn.Open(); trans = Conn.BeginTransaction(); using (SqlCommand Com = new SqlCommand(ComText, Conn, trans)) { /* DB work */ } trans.Commit(); } catch (Exception Ex) { if (trans != null) trans.Rollback(); return -1; }} 这篇关于如何使用交易就是这种情况..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-25 21:37