public static List <Relatorio> Listar(Relatorio pRelatorio) { string strConectionString = ConfigurationManager.ConnectionStrings["BradescoRI"].ConnectionString; SqlConnection objConexao = new SqlConnection(strConectionString); SqlCommand objComando = new SqlCommand("SPE_L_Relatorio"); objComando.Connection = objConexao; objComando.CommandType = CommandType.StoredProcedure; if (pRelatorio.TipoRelatorio.Id > 0) { objComando.Parameters.Add("@TipoRelatorioId", SqlDbType.Int).Value = pRelatorio.TipoRelatorio.Id; } try { //Abre Conexao objConexao.Open(); //Declara variavel de retorno List <Relatorio> objList = new List <Relatorio>(); Relatorio obj = default(Relatorio); IDataReader idrReader = default(IDataReader); idrReader = objComando.ExecuteReader(); while ((idrReader.Read())) { obj = new Relatorio(); obj.FromIDataReader(idrReader); objList.Add(obj); } return(objList); } catch (Exception ex) { throw ex; } finally { //Fecha a conexao se aberta if (objConexao.State != ConnectionState.Closed) { objConexao.Close(); } } }