Crystal Reports Workaround

There is a barely documented problem with Crystal Reports for .NET that occurs if you try to pass a dataview as a datasource to a report. The report has been built via a project dataset (XSD).

Here is the tech support entry. It has a tracking id of “CR ADAPT00117088”. I probably don’t have the latest patch but there is no reference anywhere else to this track id.

The work around is just to pull the dataview data into a new datatable. Crystal doesn’t give a sample so here is one for anyone who may be looking.

First here is the long way around if you need a table to move into a dataset.

Dim tbl As DataTable = myDataView.Table.Clone
Dim iRow As Int32
For iRow = 0 To dv.Count – 1
   
tbl.ImportRow(dv.Item(iRow).Row)
Next
mycrystalreport.SetDataSource(tbl)  ‘this assumes you only have one table for your datasource

(I need to make a confession – I have been so stung by the problem of trying to move a table from one dataset into another that I didn’t stop and think that I was sending a datatable not a dataset, so I did this the long way around. Thanks to Mike below for pointing out my silliness…see his comment for the easy way.)

  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.