1
I’d like some help. I’m using the ReportView
to generate a report from id passed as parameter:
public ActionResult Relatorio(Guid id)
{
LocalReport relatorio = new LocalReport();
//Caminho onde o arquivo do Report Viewer está localizado
relatorio.ReportPath = Server.MapPath("~/Report/RelatorioCliente.rdlc");
//Define o nome do nosso DataSource e qual rotina irá preenche-lo, no caso, nosso método criado anteriormente RepositorioPedido.SelecionaPedido(codPedido)));
relatorio.DataSources.Add(new ReportDataSource("DataSetCliente", _clienteRepositorio.BuscarTodos().AsEnumerable().FirstOrDefault(c=>c.ClienteId == id)));
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>9in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.7in</MarginTop>" +
" <MarginLeft>2in</MarginLeft>" +
" <MarginRight>2in</MarginRight>" +
" <MarginBottom>0.7in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] bytes;
//Renderiza o relatório em bytes
bytes = relatorio.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return File(bytes, mimeType);
}
But as soon as I generate the report, it gives an error on the line:
relatorio.DataSources.Add(new ReportDataSource("DataSetCliente", _clienteRepositorio.BuscarTodos().AsEnumerable().FirstOrDefault(c=>c.ClienteId == id)));
And says that:
The data source object of the report shall be of the System.Data.Datatable, System.Collections.Ienumerable or System.Web.UI.Idatasource.
Someone could give me a hand. Thank you!!