C# 事务处理

       /// <summary>
        /// 发送消息;  先插入“发件箱”表;而后插入“收件箱”(批量发送选定用户)表;
        /// </summary>
        /// <param name="parms"></param>
        /// <param name="isSend"></param>
        /// <param name="messageId"></param>
        /// <param name="allId"></param>
        /// <returns></returns>
        public static int InsertMessageToOutbox(SqlParameter[] parms, bool isSend, string messageId, string allId)
        {
            int result;
            try
            {
                SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringDefault);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    result = SqlHelper.ExecuteNonQuery(tran, CommandType.StoredProcedure, "InsertMessageToOutbox", parms);
                    if (isSend)
                    {
                        //DataTable dt=
                        BatchAddInbox(conn, allId, messageId, tran);
                    }
                    else
                    {
                        if (result > 0)
                        {
                            result = 1000;
                        }

                    }
                    tran.Commit();
                }
                catch
                {
                    tran.Rollback();
                    throw new Exception();
                }
            }
            catch
            {
                result = 0;
            }
            return result;
        }

 

posted @ 2014-06-16 14:38  kedarui  阅读(119)  评论(0编辑  收藏  举报