I have a SqlDataReader in a method and I need to return it, the problem is that when closing the SQL connection the data of SqlDataReader disappears, to what kind of data should I be able to pass it to return it ?, this is my code
static public tipoDato EjecutarSP(string sp, SqlParameter[] parametros)
{
try
{
SqlCommand command = new SqlCommand(sp, ConexionBD.con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddRange(parametros);
ConexionBD.Conectar();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
}
ConexionBD.Desconectar();
return resultado;
}
catch (Exception ex)
{
throw new Exception(" Error al ejecutar procedimiento almacenado ", ex);
}
}