[C#]分享一个以前的项目使用的DataBaseAccess类(13)


    #region DataBase Operate assistant class SQLHelper
    /// <summary>
    /// SQLHelper.
    /// </summary>
    public abstract class SQLHelper
    {
        /// <summary>
        /// DataBase ConnectionString
        /// </summary>
        public static string StrConn = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;

//------------------------------------------------------------------------------------------------------------

/// <summary>
        /// Create SqlParameter.
        /// </summary>
        /// <param>The name of the parameter to map.</param>
        /// <param>One of the System.Data.SqlDbType values.</param>
        /// <param>The length of the parameter.</param>
        /// <returns>Return new SqlParameter.</returns>
        public static SqlParameter CreateSqlParameter(string parameterName, SqlDbType DbType, object value)
        {
            SqlParameter sqlpara = new SqlParameter(parameterName, DbType);
            sqlpara.Value = value;
            return sqlpara;
        }

/// <summary>
        /// Create SqlParameter.
        /// </summary>
        /// <param>The name of the parameter to map.</param>
        /// <param>One of the System.Data.SqlDbType values.</param>       
        /// <returns>Return new SqlParameter.</returns>
        public static SqlParameter CreateSqlParameter(string parameterName, SqlDbType DbType, int size, object value)
        {           
            SqlParameter sqlpara = new SqlParameter(parameterName, DbType, size);
            sqlpara.Value = value;
            return sqlpara;
        }


        //------------------------------------------------------------------------------------------------------------

/// <summary>
        /// Param amortize Hashtable
        /// </summary>
        private static Hashtable htParamCache = Hashtable.Synchronized(new Hashtable());

/// <summary>
        /// Save Parameters in Cache
        /// </summary>
        /// <param></param>
        /// <param></param>
        public static void CacheParameters(string strCacheKey, params SqlParameter[] sqlParameters)
        {
            SQLHelper.htParamCache[strCacheKey] = sqlParameters;
        }

/// <summary>
        /// Get Parameters from Cache
        /// </summary>
        /// <param></param>
        /// <returns></returns>
        public static SqlParameter[] GetCachedParameters(string strCacheKey)
        {
            SqlParameter[] sqlParameters = (SqlParameter[])SQLHelper.htParamCache[strCacheKey];
            if (sqlParameters == null)
            {
                return null;
            }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyjwyj.html