无法使Crystal Reports vb.net 2008显示数据. [英] Cannot get Crystal Reports vb.net 2008 to display data.

查看:91
本文介绍了无法使Crystal Reports vb.net 2008显示数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用从数据库中获取并加载到数据集中的以下数据来构建CR.下面是构建数据集和设置报告的代码.我在窗体上放置了2个Datagridviews以显示数据.两个网格均显示数据,但报告未显示任何内容.

Built a CR using following data taken from a database and loaded into a dataset. Below is the code to construct the dataset and set up the report. I put 2 Datagridviews on the form to display the data. Both grids display data, but the report shows nothing.

Dim ds As New rptDataSet 'DataSet I created using the IDE
Dim t as DataTable = ds.TmsSchedule  'Primary DataTable with Source material
Dim s As DataTable = ds.School       'Second table with Student assignments
' Pull the data from the database and put it in the dataset.
Dim sc = From tms In db.TmsSchedules _
     Join sch In db.Schools On sch.SchoolDate Equals tms.schDate _
     Where tms.schDate >= firstDate And tms.schDate <= lastDate _
     Select tms.schDate, sch.SchoolDate ' etc.
Dim r As DataRow
Dim rs As DataRow
For Each dr In sc
   r = t.NewRow()
   r("schDate") = dr.schDate
       ' etc.
   t.Rows.Add(r)
   rs = s.NewRow()
   rs("SchoolDate") = dr.SchoolDate
       ' etc.
   s.Rows.Add(rs)
next
' All the above works and display in the DataGridViews on the report
' Below is exactly the same as in another report, but nothing displays.
Dim objRpt As New rptSchedule 'Report I built from the above Dataset
objRpt.SetDataSource(ds)          'Point the report to the dataset
CrystalReportViewer1.ReportSource = objRpt 'Set reportviewer to the report
CrystalReportViewer1.Refresh()    'Refresh the report.

推荐答案

代码中缺少的一件事是AcceptChanges 语句.修改数据表后,尝试添加它.

另外,由于数据集中有两个单独的数据表,因此要记住的一件事是:在报表中是否正确定义了联接,并且这些表是否具有匹配的数据.

因此,您还可以再次检查报表上的联接和/或例如使用LINQ查询检查表中是否有匹配数据.

第三件事是,使用调试器检查代码是否确实在变量s中的表中添加了行.
One thing that''s missing from the code is an AcceptChanges statement. Try adding that after you make modifications to the data table.

Also, since you have two separate data tables in the dataset, one thing that comes in mind is: Are the joins defined correctly in the report and do the tables have matching data.

So you can also double check the joins on the report and/or check for example with a LINQ query that you have matching data on the tables.

Third thing is that, using the debugger, check that the code actually adds rows to the table you have in variable s.


框中的代码是正确的代码.我没有从我的应用程序中复制代码.我输入并正确无误.
我的数据源是一个名为rptDataSet的数据集,其中定义了所有字段,但未绑定.当我声明以下内容时:
The code in the box is the correct code. I didn''t copy the code from my app. I typed it in and did it correct.
My datasource is a dataset called rptDataSet with all of the fields defined, but unbound. When I declared the following:
Dim ds As New rptDataSet 'DataSet I created using the IDE


那是我使用的数据集,但是当我声明objRpt时,我将其SetDataSource设置为rptDataSet而不是ds


That was the Dataset I used, but when I declared objRpt, I set its SetDataSource to rptDataSet instead of ds

Dim objRpt As New rptSchedule 'Report I built from the above Dataset

'***********The following statement is INCORRECT*****************
objRpt.SetDataSource(rptDataSet)

'***********The following statement is CORRECT*****************
objRpt.SetDataSource(ds)          'Point the report to the dataset

CrystalReportViewer1.ReportSource = objRpt 'Set reportviewer to the report
CrystalReportViewer1.Refresh()    'Refresh the repor




感谢大家的帮助.我仍然从大家那里学到了几点.




Thanks for help everyone. I still learned a few points from you all.


这篇关于无法使Crystal Reports vb.net 2008显示数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆