コード例 #1
0
ファイル: SQLGetListAsync.cs プロジェクト: Rushika193/Project
        /// <summary>
        /// Execute As List
        /// </summary>
        /// <typeparam name="T"><T></typeparam>
        /// <param name="StroredProcedureName">Storedprocedure Name</param>
        /// <returns></returns>
        public async Task <IList <T> > ExecuteAsListAsync <T>(string StroredProcedureName)
        {
            using (SqlConnection SQLConn = new SqlConnection(this._connectionString))
            {
                using (SqlCommand SQLCmd = new SqlCommand())
                {
                    SQLCmd.Connection  = SQLConn;
                    SQLCmd.CommandText = StroredProcedureName;
                    SQLCmd.CommandType = CommandType.StoredProcedure;
                    try
                    {
                        SqlDataReader SQLReader;
                        await SQLConn.OpenAsync();

                        SQLReader = await SQLCmd.ExecuteReaderAsync(CommandBehavior.CloseConnection); //datareader automatically closes the SQL connection

                        IList <T> mList = DataSourceHelper.FillCollection <T>(SQLReader);
                        if (SQLReader != null)
                        {
                            SQLReader.Close();
                        }
                        SQLConn.Close();
                        return(mList);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                    finally
                    {
                        SQLConn.Close();
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Execute As enumerable
        /// </summary>
        /// <typeparam name="T"><T></typeparam>
        /// <param name="StroredProcedureName">Storedprocedure Name</param>
        /// <returns></returns>
        public IEnumerable <T> ExecuteAsEnumerable <T>(string StroredProcedureName)
        {
            SqlConnection SQLConn = new SqlConnection(this._connectionString);

            try
            {
                SqlDataReader SQLReader;
                SqlCommand    SQLCmd = new SqlCommand();
                SQLCmd.Connection  = SQLConn;
                SQLCmd.CommandText = StroredProcedureName;
                SQLCmd.CommandType = CommandType.StoredProcedure;

                SQLConn.Open();
                SQLReader = SQLCmd.ExecuteReader(CommandBehavior.CloseConnection); //datareader automatically closes the SQL connection
                IEnumerable <T> mList = DataSourceHelper.FillCollection <T>(SQLReader);
                if (SQLReader != null)
                {
                    SQLReader.Close();
                }
                SQLConn.Close();
                return(mList);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                SQLConn.Close();
            }
        }
コード例 #3
0
        /// <summary>
        /// Execute As list
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="StroredProcedureName">StoreProcedure Name</param>
        /// <param name="ParaMeterCollection"></param>
        /// <returns></returns>
        public IList <T> ExecuteAsList <T>(string StroredProcedureName, List <SQLParam> ParaMeterCollection)
        {
            SqlConnection SQLConn = new SqlConnection(this._connectionString);

            try
            {
                SqlDataReader SQLReader;
                SqlCommand    SQLCmd = new SqlCommand();
                SQLCmd.Connection  = SQLConn;
                SQLCmd.CommandText = StroredProcedureName;
                SQLCmd.CommandType = CommandType.StoredProcedure;
                SqlParameter[] sqlParameters = new SQLParamCollection(ParaMeterCollection).ParamCollection;
                SQLCmd.Parameters.AddRange(sqlParameters);
                SQLConn.Open();
                SQLReader = SQLCmd.ExecuteReader(CommandBehavior.CloseConnection); //datareader automatically closes the SQL connection
                IList <T> mList = DataSourceHelper.FillCollection <T>(SQLReader);
                if (SQLReader != null)
                {
                    SQLReader.Close();
                }
                SQLConn.Close();
                return(mList);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                SQLConn.Close();
            }
        }
コード例 #4
0
ファイル: SQLGetAsync.cs プロジェクト: WARM-J/ecomx-v1
        /// <summary>
        /// Execute As Object
        /// </summary>
        /// <typeparam name="T"><T></typeparam>
        /// <param name="StroredProcedureName">StoreProcedure Name</param>
        /// <param name="ParaMeterCollection">Accept Key Value Collection For Parameters</param>
        /// <returns></returns>
        public async Task <T> ExecuteAsObjectAsync <T>(string StroredProcedureName, List <SQLParam> ParaMeterCollection)
        {
            using (SqlConnection SQLConn = new SqlConnection(this._connectionString))
            {
                using (SqlCommand SQLCmd = new SqlCommand())
                {
                    SQLCmd.Connection  = SQLConn;
                    SQLCmd.CommandText = StroredProcedureName;
                    SQLCmd.CommandType = CommandType.StoredProcedure;
                    SqlParameter[] sqlParameters = new SQLParamCollection(ParaMeterCollection).ParamCollection;
                    SQLCmd.Parameters.AddRange(sqlParameters);
                    try
                    {
                        SqlDataReader SQLReader;
                        await SQLConn.OpenAsync();

                        SQLReader = await SQLCmd.ExecuteReaderAsync(CommandBehavior.CloseConnection);

                        ArrayList arrColl = DataSourceHelper.FillCollection(SQLReader, typeof(T));
                        SQLConn.Close();
                        if (SQLReader != null)
                        {
                            SQLReader.Close();
                        }
                        if (arrColl != null && arrColl.Count > 0)
                        {
                            return((T)arrColl[0]);
                        }
                        else
                        {
                            return(default(T));
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                    finally
                    {
                        SQLConn.Close();
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Execute As Object
        /// </summary>
        /// <typeparam name="T"><T></typeparam>
        /// <param name="StroredProcedureName">Accept Key Value Collection For Parameters</param>
        /// <returns></returns>
        public T ExecuteAsObject <T>(string StroredProcedureName)
        {
            SqlConnection SQLConn = new SqlConnection(this._connectionString);

            try
            {
                SqlDataReader SQLReader;
                SqlCommand    SQLCmd = new SqlCommand();
                SQLCmd.Connection  = SQLConn;
                SQLCmd.CommandText = StroredProcedureName;
                SQLCmd.CommandType = CommandType.StoredProcedure;

                SQLConn.Open();
                SQLReader = SQLCmd.ExecuteReader();
                ArrayList arrColl = DataSourceHelper.FillCollection(SQLReader, typeof(T));
                SQLConn.Close();
                if (SQLReader != null)
                {
                    SQLReader.Close();
                }
                if (arrColl != null && arrColl.Count > 0)
                {
                    return((T)arrColl[0]);
                }
                else
                {
                    return(default(T));
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                SQLConn.Close();
            }
        }