Posted By: JakeAtCTE | Jul 3rd @ 1:13 PM
page 1 of 1
Comments: 2 | Views: 535

We have several new reports that pull data from two seperate databases and need to be able to view these reports via a Windows form.  We have been using CrystalHelper to accomplish this in the past but it does not allow for multiple data sources on a single report.  Does anyone know of a way to get CrystalHelper to do this or knows of another way to display reports with multiple data sources in a Windows form?   We are using C# in .Net 2.0

Your help is appreciated,
Jake

If you are within windows forms, why are you allowing the report to bind directly to one or more data sources?  Why not bind to a data set which is in your application.  Doing this will allow you to have multiple data sources.  Yes this is a bit more complex however it gives you complete control of data which is the crystal reports uses.  It also allows you to manage the database connections yourself.

How to do this:

  1. Add a data set to your project
  2. Add one or more data tables to your data set.  Each data table should contain precisely what your report is expecting.  Use the same table names and columns expected by your report.
  3. Once you have completed step 2 you can actually build the report from your datasource.  Crystal will automatically use fake data during the design phase.
  4. At runtime, run as many queries as required to populate the data needed by your report.  These queries should place their results into your data set.  As you are doing the query, you can use any data source you want and perform any actions you need.  I have even gone so far as use a dataview to peform additional actions upon a dataset prior to binding to a report.
  5. Bind your report to the data set and show the report.

Sample pseudo code:

                    dDA = new System.Data.SqlClient.SqlDataAdapter(dCMD); // open sql query
                    dDS = new System.Data.DataSet(); // create a blank dataset
                    dDA.Fill(dDS, "tblTicketsByQueue"); // populate dataset with table expected by report
                    crp = CreateReportViewer(ref frm); // create a crystal report object.  This routine creates the viewer on the specified form

                    // have report use our report anme
                    rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                    rd.Load(sReportName); // load the report from specified file

                    rd.SetDataSource(dDS);  //  have report use our dataset.  This does the binding
                    crp.ReportSource = rd; // set the viewer to display our report

                     crp.Show(); // show the viewer which will show the report
                     frm.Show(); // show the form which holds the viewer


While this sample uses a SQL server as its data source you could equally create the dataset completely from scratch.


Thanks for the response, but it looks like it won't work in this case.  What I tried was getting the SQL to generate the dataset from the report itself, that way adding reports is as easy as dropping them in the directory.  But after some research it looks like there is no way to get the SQL needed out of the report.  With the amount of reports we use and the number of new reports being generated storing the SQL needed in a database table is not a good solution.  We really need the ability to be able to drop the report into a directory and have it work.  Any other ideas?

Thanks,
Jake

page 1 of 1
Comments: 2 | Views: 535