日期:2014-05-16 浏览次数:20677 次
//下面是我简单写的两个DataReader的helper方法
public static SqlDataReader ExecuteReader(string _sqlStr, params SqlParameter[] _commandParameters)
{
SqlConnection conn = new SqlConnection(connStr);
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
SqlCommand cmd = new SqlCommand(_sqlStr, conn);
cmd.Parameters.Clear();
if (_commandParameters != null && _commandParameters.Length > 0)
{
cmd.Parameters.AddRange(_commandParameters);
}
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
public static List<object> GetModelList(Type model, string _sqlStr, params SqlParameter[] _commandParameters)
{
using (SqlConnection conn = new SqlConnection(connStr))
{
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
using (SqlCommand cmd = new SqlCommand(_sqlStr, conn))
{
cmd.Parameters.Clear();
if (_commandParameters != null && _commandParameters.Length > 0)
{
cmd.Parameters.AddRange(_commandParameters);
&nbs