Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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.

  
Posted 31-Aug-12 4:39am
Edited 31-Aug-12 5:07am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Andrew Alix at 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.
Mika Wendelius at 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 at 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.
Mika Wendelius at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 886
1 OriginalGriff 390
2 CPallini 255
3 Volynsky Alex 205
4 Richard Deeming 175
0 OriginalGriff 5,540
1 Sergey Alexandrovich Kryukov 4,668
2 CPallini 4,540
3 George Jonsson 3,102
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 2 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100