原創- -資料層

來源:互聯網
上載者:User
1總合了n種資料訪問層……——……不是很成熟
2. 由於鄙人的懶惰缺少了-傳遞參數(這部分設計完了但是~~懶得寫分析原諒哈),這部分主要採用緩衝參數的設計.
3.缺少DAL.SqlClient.SqlParametersAll.SqlText枚舉的定義他用來封裝所有的預存程序的名稱
4.將要呈現給大家的是一部分中的部分哈~~原因鄙人懶惰~~造成的~~檢討中

        public ExecState Exec(DAL.SqlClient.SqlParametersAll.SqlText commandText)
        {

            ExecState ren = new ExecState();
            System.Data.SqlClient.SqlConnection sqlCon=new System.Data.SqlClient.SqlConnection(this.ConnectionString);
            
            System.Data.SqlClient.SqlCommand sqlCommand = new System.Data.SqlClient.SqlCommand(
            Enum.GetName(typeof(DAL.SqlClient.SqlParametersAll.SqlText), commandText), sqlCon);

            sqlCommand.CommandType = CommandType.StoredProcedure;
            
            try
            {
                sqlCon.Open();
                sqlCommand.Transaction = sqlCon.BeginTransaction();

                //---------------------記錄影響的行數
                ren.State.Add("NonQuery", sqlCommand.ExecuteNonQuery());

                //---尋找輸出參數
                this.SelectOuputParameters(ren, sqlCommand.Parameters);



                //--成功提交
                sqlCommand.Transaction.Commit();
            }
            catch (System.Data.SqlClient.SqlException exp)
            {
                //--失敗了復原
                sqlCommand.Transaction.Rollback();
            }
            finally
            {
                if (sqlCon.State == ConnectionState.Open)
                {
                    sqlCon.Close();
                    sqlCon.Dispose();
                }
            }

            return ren;
        }

        //--尋找輸出參數
        
        /**//// <summary>
        /// 尋找輸出參數,不用返回資料因為是按引用傳遞的
        /// </summary>
        /// <param name="ren"></param>
        /// <param name="SelectPr"></param>
        private void SelectOuputParameters(ExecState ren, System.Data.SqlClient.SqlParameterCollection SelectPr)
        {
            foreach (System.Data.SqlClient.SqlParameter OnLyPr in SelectPr)
            {
                if (OnLyPr.Direction ==ParameterDirection.InputOutput || OnLyPr.Direction == ParameterDirection.Output)
                {
                    ren.State.Add(OnLyPr.ParameterName, OnLyPr.Value);
                }
            }

        }


    }

    //------------執行後的狀態
    public class ExecState
    {
        //-----------------------------------------儲存對應的資料存放區在那個組中
        public System.Collections.Generic.Dictionary<string, object> State = new  System.Collections.Generic.Dictionary<string,object>();
   
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.