CREATE PROCEDURE ProductOrderSplit @SELL_IDSN int, @SplitNumber int AS begin tran declare @SELL_ID varchar(100) declare @OrderNoteSN int select @SELL_ID=SELL_ID,@OrderNoteSN=OrderNoteSN from C_SENDPRODUCTDETAIL where SELL_IDSN=@SELL_IDSN if(@@error<>0)goto errhandle begin insert into C_SENDPRODUCTDETAIL (SELL_ID,OrderNoteSN ) values (@SELL_ID,@OrderNoteSN ) update C_SENDPRODUCTDETAIL set CUS_ENSURENUM=CUS_ENSURENUM-@SplitNumber where SELL_IDSN=@SELL_IDSN commit tran end if(@@error<>0)goto errhandle errhandle: begin if (@@error<>0) rollback tran end GO
C# code
public int SplitProduct(int SELL_IDSN, int SplitNumber) { SqlConnection sqlConn = HunryCommon.DataAccess.GetConnection(); sqlConn.Open(); SqlTransaction sqlTrans = sqlConn.BeginTransaction(); try { SqlParameter [] commandParameters = new SqlParameter[2]; commandParameters[0] = new SqlParameter("@SELL_IDSN",SqlDbType.Int); commandParameters[0].Value = SELL_IDSN; commandParameters[1] = new SqlParameter("@SplitNumber",SqlDbType.Int); commandParameters[1].Value = SplitNumber; HunryCommon.DataAccess.ExecuteScalar(sqlTrans,CommandType.StoredProcedure,"ProductOrderSplit",commandParameters); sqlTrans.Commit(); sqlConn.Close(); return 1; } catch(SqlException ex) { string ss=ex.ToString(); sqlTrans.Rollback(); sqlConn.Close(); return 0;//有异常 } }