/** 说明:数据库助手类*/ using System; using ; using ; using ; using ; using ; using ; namespace DAL { public class SQLHelper { private SqlConnection conn = null ; private mand cmd = null ; private SqlDataReader sdr = null ; public SQLHelper() { string connStr = ConfigurationManager .ConnectionStrings[ "connStr" ].ConnectionString; conn = new SqlConnection (connStr); } private SqlConnection GetConn() { if ( == ConnectionState .Closed) { (); } return conn; } /// <summary> /// 执行不带参数的增删改 SQL 语句或存储过程/// </summary> /// <param name="cmdText"> 增删改 SQL 语句或存储过程</param> /// <param name="ct"> 命令类型</param> /// <returns></returns> public int ExecuteNonQuery( string cmdText, CommandType ct) { int res; try { cmd = new mand (cmdText, GetConn()); mandType = ct; res = (); } catch ( Exception ex) { throw ex; } finally { if ( == ConnectionState .Open) { (); }} return res; } /// <summary> /// 执行带参数的增删改 SQL 语句或存储过程/// </summary> /// <param name="cmdText"> 增删改 SQL 语句或存储过程</param> /// <param name="ct"> 命令类型</param> /// <returns></returns> public int ExecuteNonQuery( string cmdText, SqlParameter [] paras, CommandType ct) { int res; using (cmd = new mand (cmdText, GetConn())) { mandType = ct; (paras); res = (); } return res; } /// <summary> /// 执行查询 SQL 语句或存储过程/// </summary> /// <param name="cmdText"> 查询 SQL 语句或存储过程</param> /// <param name="ct"> 命令类型</param> /// <returns></returns> public DataTable ExecuteQuery( string cmdText, CommandType ct) { DataTable dt= new DataTable (); cmd = new mand (cmdText, GetConn()); mandType = ct; using (sdr = ( CommandBehavior .CloseConnection)) { (sdr); } return dt; } /// <summary> /// 执行带参数的查询 SQL 语句或存储过程/// </summary> /// <param name="cmdText"> 查询 SQL 语句或存储过程</param> /// <param name="paras"> 参数集合</param> /// <param name="ct"> 命令类型</param> /// <r
新闻发布系统设计源码 来自淘豆网m.daumloan.com转载请标明出处.