我的存储过程是这样子的,你的意思是不是不需要在储存过程里面编rollback呢?USE [CapitalManager] GO /****** Object: StoredProcedure [dbo].[PRODUCT_NETVALUE] Script Date: 06/05/2012 15:29:53 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[PRODUCT_NETVALUE] (@PDATE DATE) AS BEGIN BEGIN TRANSACTION BEGIN TRY declare curproduct insensitive cursor for select productid from product declare @productid int open curproduct fetch next from curproduct into @productid while @@FETCH_STATUS=0 begin --计算产品净值 DECLARE @new_tc float DECLARE @add_money float DECLARE @new_net float DECLARE @new_tq float DECLARE @pre_tq float set @new_tc=(select sum(TC) from PRODUCT_Q where ProductID=@PRODUCTID group by ProductID) if (select SUM(AddMoney) from Distribute where ProductID=@PRODUCTID and states=1 group by ProductID) is null set @add_money=0.0 else set @add_money=(select SUM(AddMoney) from Distribute where ProductID=@PRODUCTID and states=1 group by ProductID) set @pre_tq=(select top 1 TPQ from ProductCapital where ProductID=@PRODUCTID order by ID desc) set @new_net=(@new_tc-@add_money)/@pre_tq set @new_tq=@pre_tq+@add_money/@new_net insert into ProductCapital(ProductID,PDate,NetPC,TPC,TPQ,PCchange) values(@PRODUCTID,@PDATE,@new_net,@new_tc,@new_tq,@add_money) update Distribute set states=2 where ProductID=@PRODUCTID and states=1 fetch next from curproduct into @productid end close curproduct deallocate curproduct COMMIT TRANSACTION END TRY BEGIN CATCH rollback transaction END CATCH END
private SqlTransaction _tran;
/// <summary>
/// 开启事务
/// </summary>
public void BeginTran()
{
_tran = this._con.BeginTransaction();
}
/// <summary>
/// 提交事务
/// </summary>
public void CommitTran()
{
this._tran.Commit();
}
/// <summary>
/// 回滚事务
/// </summary>
public void RollBackTran()
{
this._tran.Rollback();
}
GO
/****** Object: StoredProcedure [dbo].[PRODUCT_NETVALUE] Script Date: 06/05/2012 15:29:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[PRODUCT_NETVALUE]
(@PDATE DATE)
AS
BEGIN
BEGIN TRANSACTION
BEGIN TRY
declare curproduct insensitive cursor
for select productid from product
declare @productid int
open curproduct
fetch next from curproduct into @productid
while @@FETCH_STATUS=0
begin
--计算产品净值
DECLARE @new_tc float
DECLARE @add_money float
DECLARE @new_net float
DECLARE @new_tq float
DECLARE @pre_tq float
set @new_tc=(select sum(TC) from PRODUCT_Q where ProductID=@PRODUCTID group by ProductID)
if (select SUM(AddMoney) from Distribute where ProductID=@PRODUCTID and states=1 group by ProductID) is null
set @add_money=0.0
else
set @add_money=(select SUM(AddMoney) from Distribute where ProductID=@PRODUCTID and states=1 group by ProductID)
set @pre_tq=(select top 1 TPQ from ProductCapital where ProductID=@PRODUCTID order by ID desc)
set @new_net=(@new_tc-@add_money)/@pre_tq
set @new_tq=@pre_tq+@add_money/@new_net
insert into ProductCapital(ProductID,PDate,NetPC,TPC,TPQ,PCchange) values(@PRODUCTID,@PDATE,@new_net,@new_tc,@new_tq,@add_money)
update Distribute set states=2 where ProductID=@PRODUCTID and states=1
fetch next from curproduct into @productid
end
close curproduct
deallocate curproduct
COMMIT TRANSACTION
END TRY
BEGIN CATCH
rollback transaction
END CATCH
END