我的数据集中有数据,但它没有显示在我的报表查看器中?

发布于 2025-01-08 13:20:40 字数 906 浏览 0 评论 0原文

我有一个在 datagridview 中显示数据的程序。 datagridview 中的数据来自数据集中的表。数据在屏幕上看起来不错,因此我决定添加一种打印数据的方法。

我创建了一个新表单,添加了一个报表查看器控件,并设计了报表。我使用我的数据集作为报告的数据源。

然后,我在原始表单中添加了一个按钮,这样当按下该按钮时,它将显示带有报表查看器控件的表单。

我的问题是,当我点击打印按钮时,它会将我带到报表查看器控件表单,但它显示的报表仅包含标题,没有数据。就像我的数据集中没有数据一样!但是,当我进行调试时,它在我的数据集中显示了 1000 多行。

所以,我的问题是,我忘记做什么?数据就在那里,它显示在一种表单上(使用 datagridview),但不会显示在报表查看器控件上(仅显示标题)。

实际上没有涉及任何编码。我刚刚制作了一个新表单,添加了报表查看器控件,设计了报表并告诉它使用我的数据集作为数据源。通常,这对我有用。我无法想象为什么它不起作用。

感谢您的任何帮助或建议!

这是我用来显示报告的代码:

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

这是我的两个屏幕的图像。数据显然在我的数据集中,否则第一个屏幕上就没有数据。不过,第二个屏幕似乎显示我的数据集为空,因为除了标题之外什么都没有出现。

在此处输入图像描述

在此输入图像描述

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昔梦 2025-01-15 13:20:40

我认为您缺少 dataBind 方法:

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 reports

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

世界如花海般美丽 2025-01-15 13:20:40

支持视频 https://www.youtube.com/watch?v=hkDIDTNbA6M

u需要再次将数据从数据库添加到您的数据集中

 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();

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文