Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

VB
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.
Posted
Updated 31-Aug-12 5:07am
v3

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.
 
Share this answer
 
Comments
Andrew Alix 1-Sep-12 9:41am    
Checked all of that. In fact I set up two dataGridViews and all the data appears in the GridViews. Appreciate the AcceptChanges suggestion though.
Wendelius 1-Sep-12 12:06pm    
So you're sure that the tables contain data before they are sent to CR? Also one thing you could try is to remove the joins from Crystal. That should cause a cartesian product and if the data appears then, there is something wrong with the join definitions.
Andrew Alix 2-Sep-12 13:20pm    
Acually, I found the error. So stupid. The code in the box above is correct, but it wasn't correct in the application. Using the above code, the data displays correctly. I would have never seen it if I had just copied the code into the example.
Wendelius 2-Sep-12 13:52pm    
Well, the most important thing is that it got solved :)

That often happens to all of us and when you start to explain the situation to someone else, suddenly you see very clearly why the problem exists.
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:
VB
Dim ds As New rptDataSet 'DataSet I created using the IDE

That was the Dataset I used, but when I declared objRpt, I set its SetDataSource to rptDataSet instead of ds
VB
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900