我的数据集中有数据,但它没有显示在我的报表查看器中?
我有一个在 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您缺少 dataBind 方法:
From the Exam 70-516: TS: Accessing Data with Microsoft .NET Framework 4:
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:
add it to the form load event on your form report
支持视频 https://www.youtube.com/watch?v=hkDIDTNbA6M
u需要再次将数据从数据库添加到您的数据集中
video for support https://www.youtube.com/watch?v=hkDIDTNbA6M
u need to again add data into ur dataset from database