好的,所以我有一个网络表单和 5 个 FileUpload 控件..用户可以上传从 1 到 5 的任意数量的文件,但如果这些文件中的任何一个没有上传,那么我想回滚所有内容......例如:如果用户选择了4 个文件,如果在第 4 个发生意外情况,那么我想删除或回滚所有之前的 3 个文件上传.. 我试过这个..
try
{
using (TransactionScope scope = new TransactionScope())
{
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
scope.Complete();
}//end of transactionscope
}
catch { }
'dboperation' 是 c# 文件中的一个类,'dbinsert' 是一个执行插入存储过程的方法。我的猜测是我需要使用事务范围,但我不确定我是否正确,即使我应该如何实现这一目标?