Error message when generating report

Asked

Viewed 102 times

1

I’m making a report and it’s giving an error message that I’m not finding a solution.

Error:

inserir a descrição da imagem aqui

Code Generate button

   private void btnGerarRelatorio_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter da = new SqlDataAdapter();
        DataSet dsum = new DataSet();
        DataTable oTable = new DataTable();

        String strReportPath = "";
        try
        {
            strReportPath = @"Report4.rdlc";
            reportViewer1.LocalReport.ReportPath = strReportPath;
            SqlConnection conn = new SqlConnection(@"Data Source=DENILSON-PC;Initial Catalog=dbSistEstoqueEmp;Integrated Security=True");

            cmd.Connection = conn;
            cmd.CommandText = "SELECT * FROM tbEntradaEstoque WHERE cod_peca = @codPeca AND data_ent BETWEEN @dataEnt AND @dataEnt1";
            cmd.CommandType = CommandType.Text;
            conn.Open();
            cmd.Parameters.Add("codPeca", SqlDbType.Int).Value = Convert.ToInt32(txtCodPeca.Text);
            cmd.Parameters.Add("dataEnt", SqlDbType.DateTime).Value = Convert.ToDateTime(maskDataInicial.Text).Date;
            cmd.Parameters.Add("dataEnt1", SqlDbType.DateTime).Value = Convert.ToDateTime(maskDataFinal.Text).Date;

            SqlDataReader oDataReader = cmd.ExecuteReader();
            oTable.Load(oDataReader);
            ReportDataSource myReportDataSource = new ReportDataSource("dbEntSaidaPeca", oTable);
            reportViewer1.Clear();
            reportViewer1.LocalReport.DataSources[0] = myReportDataSource;
            reportViewer1.RefreshReport();


        }
        catch (Exception ex)
        {

            MessageBox.Show(ex.Message);
        }
    }

1 answer

1


The name of Dataset passed as argument of ReportDataSource should be the same as the one configured in the RDLC file of the report. Then the creation of Reportdatasource should be:

 ReportDataSource myReportDataSource = new ReportDataSource("DataSet1", oTable);
  • Thank you very much helped me, let me ask you to get 2 tables tbEntradaPeca and tbSaidaPeca how would I do that in the report ? I would choose a piece Cod 1 starting date and end date and show me all the entries and exit in the report of this piece, if you can help me I appreciate I need to deliver this day 12 in college.

Browser other questions tagged

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