I would like some help. I am using ReportView
to generate a report from the 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 at the time I'm going to 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 report data source object must be of type System.Data.DataTable, System.Collections.IEnumerable, or System.Web.UI.IDataSource.
Someone could give me a hand. Thank you !!