设为首页 加入收藏

TOP

[C#]分享一个以前的项目使用的DataBaseAccess类(八)
2014-11-24 14:34:34 来源: 作者: 【 】 浏览:13
Tags:分享 一个 以前 项目 使用 DataBaseAccess
ow;
}
finally
{
this.conn.Close();
}
}


}


#endregion


#endregion


#region other


///


///Close DataBase Connection.
///

public void CloseDB()
{
if (this.conn != null)
{
if (this.conn.State != ConnectionState.Closed)
this.conn.Close();
}
}

///
/// Dispose Resource
///

public void Dispose()
{
if (this.conn != null)
{
if (this.conn.State != ConnectionState.Closed)
this.conn.Close();
this.conn.Dispose();
}
}
#endregion
}


#endregion



#region DataBase Operate assistant class SQLHelper
///


/// SQLHelper.
///

public abstract class SQLHelper
{
///
/// DataBase ConnectionString
///

public static string StrConn = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;


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


///


/// Create SqlParameter.
///

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


///


/// Create SqlParameter.
///

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



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


///


/// Param amortize Hashtable
///

private static Hashtable htParamCache = Hashtable.Synchronized(new Hashtable());


///


/// Save Parameters in Cache
///

///
///
public static void CacheParameters(string strCacheKey, params SqlParameter[] sqlParameters)
{
SQLHelper.htParamCache[strCacheKey] = sqlParameters;
}


///


/// Get Parameters from Cache
///

///
///
public static SqlParameter[] GetCachedParameters(string strCacheKey)
{
SqlParameter[] sqlParameters = (SqlParameter[])SQLHelper.htParamCache[strCacheKey];
if (sqlParameters == null)
{
return null;
}


SqlParameter[] clonedParms = new SqlParameter[sqlParameters.Length];
for (int i = 0, j = sqlParameters.Length; i < j; i++)
{
clonedParms[i] = (

首页 上一页 5 6 7 8 9 10 下一页 尾页 8/10/10
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C# 在winform画面上点击某个区域.. 下一篇C#中生成验证码的类

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: