PASSING DATASET TO REPORT VIEWER

Ahmed Algosaibi

Total Post:1

Points:7
Posted by  Ahmed Algosaibi
C# 
C#
 2465  View(s)
Ratings:
Rate this:
Hello guys,
I've windows app that uses report viewer, but the problem that I don't get result back?

This is my code.

private void Form3_Load(object sender, EventArgs e)
        {
            con.ConnectionString = connection.x;

            runRptViewer();
        }

        private DataTable getData()
    {
       
            con.Open();
            DataSet1 dss = new DataSet1();
            string sql = "select product_id, product_name,product_quantity from product";
            SqlDataAdapter da = new SqlDataAdapter(sql, con);
            da.Fill(dss);
            DataTable dt = dss.Tables["product"];

        return dt;
    }

    private void runRptViewer()
    {      
            reportViewer1.LocalReport.DataSources.Clear(); //clear report
            reportViewer1.LocalReport.ReportEmbeddedResource = "Report1.rdlc"; // bind reportviewer with .rdlc
            Microsoft.Reporting.WinForms.ReportDataSource dataset = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", getData()); // set the datasource
            reportViewer1.LocalReport.DataSources.Add(dataset);
            reportViewer1.LocalReport.Refresh();
            reportViewer1.RefreshReport();
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!