Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.NET DataSet in memory - how to load into CR report? 1

Status
Not open for further replies.

hapax

Programmer
Nov 10, 2006
105
US
My .NET web app has a DataSet in memory. It includes several tables.

How can I hook Crystal Reports XI into this data?
Can it be done without writing the dataset to a physical file?

I know basically how to use the ReportDocument in .NET code. But I don't know the best way to pass a DataSet in memory to CR.
 
I've done this in several Winforms programs and it's not too difficult. I'm going to assume that you have one form for generating the dataset and another for the report viewer. Here's what I do.

1. In the viewer form, add a DataSet variable and property to the form.
2. In the Set code for the DataSet property, set the datasource for the report to the value being passed in.
3. In the code that runs the viewer, Create the viewer form and then set the DataSet property prior to viewing the form

Here's some sample code. I work in C#, so if you're using VB.NET, you'll have to translate this as well as modifying it to work with ASP.NET.

Viewer Code
Code:
public partial class MyRptViewer : Form
{
  DataSet rptDS;
  MyReport rpt = null;
  
  public MyRptViewer()
  {
    InitializeComponent();
    rpt = new CrystalDocReport();
  }
    
  public DataSet ReportDataSet
  {
    Set
    {
      reportDS = value;
      rpt.SetDataSource(reportDS);
      viewer.ReportSource := rpt;
    }
  }
}
Calling code
Code:
  MyRptViewer viewer = new MyRptViewer();
  viewer.ReportDataSet = myDataSet;
  viewer.Show();

-Dell


A computer only does what you actually told it to do - not what you thought you told it to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top