Exemplo n.º 1
0
        //************************************************************************
        /// <summary>
        /// プロシージャを実行して、オブジェクトを返す
        /// </summary>
        /// <param name="strSPName">プロシージャの名称</param>
        /// <param name="list">DBアクセスパラメータリスト</param>
        /// <param name="objReturn">戻るのオブジェクト</param>
        /// <returns>正常の場合はtrueを返す、それ以外の場合はfalse。</returns>
        //************************************************************************
        public bool ExecSp(string strSPName, ArrayList list, ref object objReturn, string ConnStr)
        {
            bool           bReturn   = false;
            SqlConnection  conn      = (SqlConnection)SQLDataConnection.GetConnection(ConnStr);
            SqlCommand     dbCommand = new SqlCommand(strSPName, conn);
            SQLTransaction trans     = new SQLTransaction(conn);

            if (trans.IsBegin())
            {
                dbCommand.Transaction = (SqlTransaction)trans.GetCurrentTransaction();
            }
            dbCommand.CommandType    = CommandType.StoredProcedure;
            dbCommand.CommandTimeout = 36000;
            SqlParameter SqlParam = null;

            try
            {
                if (list != null)
                {
                    IEnumerator Enumerator;
                    Enumerator = list.GetEnumerator();
                    NcPara para;
                    while (Enumerator.MoveNext())
                    {
                        para = (NcPara)Enumerator.Current;
                        if (Equals(para.OutPut, true))
                        {
                            SqlParam = dbCommand.Parameters.Add(GetSqlParameter(para.Key, (SqlDbType)para.Type, para.Size, para.Value, para.OutPut));
                        }
                        else
                        {
                            dbCommand.Parameters.Add(GetSqlParameter(para.Key, (SqlDbType)para.Type, para.Size, para.Value, para.OutPut));
                        }
                    }
                }

                dbCommand.ExecuteNonQuery();
                if (SqlParam != null && objReturn != null)
                {
                    objReturn = SqlParam.Value;
                }
                bReturn = true;
            }
            catch (Exception err)
            {
                // NdnPublicFunction.WriteLog(m_strLogFileName, err.Message);
                NCLogger.GetInstance().WriteExceptionLog(err);
            }
            finally
            {
                dbCommand.Parameters.Clear();
            }
            return(bReturn);
        }
Exemplo n.º 2
0
        //************************************************************************
        /// <summary>
        /// プロシージャを実行して、データセットを返す
        /// </summary>
        /// <param name="strSPName">プロシージャの名称</param>
        /// <param name="list">DBアクセスパラメータリスト</param>
        /// <param name="dataSet">戻るのデータセット</param>
        /// <param name="strTable">テーブルの名前</param>
        /// <returns>正常の場合はtrueを返す、それ以外の場合はfalse。</returns>
        //************************************************************************
        public bool ExecSp(string strSPName, ArrayList list, ref DataSet dataSet, string strTable, string ConnStr)
        {
            bool bReturn = false;

            if (dataSet == null)
            {
                dataSet = new DataSet();
            }
            SqlConnection  conn      = (SqlConnection)SQLDataConnection.GetConnection(ConnStr);
            SqlCommand     dbCommand = new SqlCommand(strSPName, conn);
            SQLTransaction trans     = new SQLTransaction(conn);

            if (trans.IsBegin())
            {
                dbCommand.Transaction = (SqlTransaction)trans.GetCurrentTransaction();
            }
            dbCommand.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter dbAdapter = null;

            try
            {
                if (list != null)
                {
                    IEnumerator Enumerator;
                    Enumerator = list.GetEnumerator();
                    NcPara para;
                    while (Enumerator.MoveNext())
                    {
                        para = (NcPara)Enumerator.Current;
                        dbCommand.Parameters.Add(GetSqlParameter(para.Key, (SqlDbType)para.Type, para.Size, para.Value, para.OutPut));
                    }
                }
                //アダプターの構成
                dbAdapter = new SqlDataAdapter(dbCommand);

                dbAdapter.Fill(dataSet, strTable);
                bReturn = true;
            }
            catch (Exception err)
            {
                // NdnPublicFunction.WriteLog(m_strLogFileName, err.Message);
                NCLogger.GetInstance().WriteExceptionLog(err);
            }
            finally
            {
                dbCommand.Parameters.Clear();
                dbAdapter.Dispose();
            }
            return(bReturn);
        }