其ExecuteReader的参数是(CommandType commandType, string commandText, params SqlParameter[] commandParameters)
然后我想用它创建一个SqlDatareader对象
我是这么写的 SqlDataReader dr = DAL.NewSqlHelper.ExecuteReader(CommandType.Text, sql2, paras);
没有报错但是一运行就不对了,提示dr一直都为空,在while(dr.Read())处就出错了
这是NewSqlHelper.ExecuteReader的代码
public static SqlDataReader ExecuteReader(CommandType commandType, string commandText, params SqlParameter[] commandParameters) { if (constring == null || constring.Length == 0) throw new ArgumentNullException("connectionString"); SqlConnection connection = null; try { connection = new SqlConnection(constring); connection.Open(); return SqlHelper.ExecuteReader(connection, null, commandType, commandText, commandParameters, SqlConnectionOwnership.Internal); } catch { // If we fail to return the SqlDatReader, we need to close the connection ourselves if (connection != null) connection.Close(); throw; }
} 是底层方法跳转除了点错
|