Kevin
Kevin

Reputation: 4848

I have data in my dataset, but it's not showing up in my reportviewer?

I have a program that shows data in a datagridview. The data in the datagridview comes from a table in a dataset. The data looks good on the screen so I decided to add a way to print the data.

I created a new form, added a reportviewer control, and designed the report. I used my dataset as the datasource for the report.

I then added a button to my original form so that when it was pressed, it would show the form with the reportviewer control.

My problem is, when I hit the print button, it takes me to my reportviewer control form, but it shows my report with only the headings, no data. It's like my dataset has no data in it! But, when I step through with debug, it shows over 1000 rows in my dataset.

So, my question is, what have I forgotten to do? The data is there, it shows up on one form (with the datagridview) but it doesn't show up on the reportviewer control (only the headings).

There was really no coding involved. I just made a new form, added the reportviewer control, designed the report and told it to use my dataset as the datasource. Typically, this works for me. I can't imagine why it's not working.

Thanks for any help or advice!

Here's the code that I use to show the report:

private void btnPrint_Click(object sender, EventArgs e)
    {
        Form showReport = new frmPrintView();
        showReport.Show();
    }

Here are images of my two screen. The data is obviously in my dataset, otherwise there would be none on the first screen. The second screen, though, seems to show my dataset as being empty since nothing appears but the headings.

enter image description here

enter image description here

Upvotes: 0

Views: 5208

Answers (2)

Ganesh Sundaram
Ganesh Sundaram

Reputation: 72

video for support https://www.youtube.com/watch?v=hkDIDTNbA6M

u need to again add data into ur dataset from database

 billDataSet b1 = new billDataSet();

SqlDataAdapter s = new SqlDataAdapter("select * from TblOrder",con);

s.Fill(b1,b1.Tables[0].TableName);

ReportDataSource rds = new ReportDataSource("orders",b1.Tables[0]);

this.reportViewer1.LocalReport.DataSources.Clear();

this.reportViewer1.LocalReport.DataSources.Add(rds);

this.reportView er1.LocalReport.Refresh();

this.TblOrderTableAdapter.Fill(this.billDataSet.TblOrder, d1.ToString(),d2.ToString(), companyid);

this.reportViewer1.RefreshReport();

Upvotes: 0

Diego
Diego

Reputation: 36176

I think you are missing the dataBind method:

From the Exam 70-516: TS: Accessing Data with Microsoft .NET Framework 4:

ASP.NET controls require you to execute the DataBind method on the control to indicate
that the data is ready to be rendered. If you don’t execute the DataBind method, the control won’t render. When executing the DataBind method on a control, the control is obliged to call the DataBind method on its child controls. This means that you can execute the DataBind method on the Web form, and it will call the DataBind method on all its controls

add it to the form load event on your form report

Upvotes: 2

Related Questions