日期:2014-05-17 浏览次数:20453 次
public abstract class SQLHelper
{
/// <summary>
/// 连接字符串
/// </summary>
public static readonly string ConnectionString = "数据库连接字符串";
private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());
/// <summary>
/// 数据库增,删,改方法
/// </summary>
/// <param name="connectionString">连接字符串 </param>
/// <param name="cmdType">Command类型 </param>
/// <param name="cmdText">执行文本 </param>
/// <param name="commandParameters">参数 </param>
/// <returns> </returns>
public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
using (SqlConnection conn = new SqlConnection(connectionString))
{
PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
/// <summary>a
/// 数据库增,删,改方法
/// </summary>
/// <param name="connection">连接对象 </param>
/// <param name="cmdType">Command类型 </param>
/// <param name="cmdText">执行文本 </param>
/// <param name="commandParameters">参数 </param>
/// <returns> </returns>
public static int ExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
/// <summary>
/// 数据库增,删,改方法
/// </summary>
/// <param name="trans">事务 </param>
/// <param name="cmdType">Command类型 </param>
/// <param name="cmdText">执行文本 </param>
/// <param name="commandParameters">参数 </param>
/// <returns> </returns>
public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
int val = cmd.ExecuteNonQuery();