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:
- Add a data set to your project
- 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.
- 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.
- 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.
- 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.