error when assigning a query to fill a reportview

Asked

Viewed 112 times

0

can give me a template for a popular Rpt without DATASET?

what I use is not working. , follows the model I use.

private void Carregar()
{

DateTime dt1; dt1 = dtpickerInicial.Value;
            DateTime dt2; dt2 = dtpickerFinal.Value;

        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter da = new SqlDataAdapter();
        DataSet dsum = new DataSet();
        DataTable oTable = new DataTable();
        string strReportPath = "";

        try
        {
            strReportPath = @"rptRelatorioCaixa.rdlc";
            reportViewer1.LocalReport.ReportPath = strReportPath;
            SqlConnection conn = new SqlConnection(Properties.Settings.Default.BD_OneDrive );
            cmd.Connection = conn;
            cmd.CommandText = "SELECT * FROM CAIXA"; // Where dataSaida between @dtini and @dtfim ";

            cmd.CommandType = CommandType.Text;
            conn.Open();

            SqlDataReader oDataReader = cmd.ExecuteReader();
            oTable.Load(oDataReader);
            ReportDataSource myReportDataSource = new ReportDataSource(oTable);// da erro pois me cobra um dataSet
            reportViewer1.LocalReport.EnableExternalImages = true;
            //ReportParameter p = new ReportParameter("Titulo", "Resultado parcial do mes");
            //this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p });

            reportViewer1.Clear();
            if (reportViewer1.LocalReport.DataSources.Count > 0)
                reportViewer1.LocalReport.DataSources[0] = myReportDataSource;
            else
                reportViewer1.LocalReport.DataSources.Add(myReportDataSource);

            reportViewer1.RefreshReport();
  • Remember to add the language tag as well.

1 answer

0

I use the following method: in it I pass a dictionary, where the key is name of the dataset(dataset configured in rdlc, not a Dataset of System.Data), and in the dictionary value is a Ienumerable, which can be anything that implements Ienumerable as List. I use dictionary for more complex reports that need more than one data source.

        private void InicializarRelatorio(string nomeRelatorio, Dictionary<string, IEnumerable> dados)
        {
            //percorre o dicionario para adicionar as fontes de dados no relatorio
            foreach (var dado in dados)
            {
                ReportDataSource reportDataSource = new ReportDataSource();
                reportDataSource.Name = dado.Key; //nome do DataSet no .rdlc
                reportDataSource.Value = dado.Value; // objeto(lista) de dados
                reportViewer.LocalReport.DataSources.Add(reportDataSource);
            }

            //carrega o relatorio que deve estar na pasta do executavel. o arquivo rdlc deve estar CopyToLocal
            reportViewer.LocalReport.ReportPath = AppDomain.CurrentDomain.BaseDirectory + @"Relatorios\" + nomeRelatorio;
            reportViewer.RefreshReport();
        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.