It took me a while but I got it figured out, it was my first time attempting to use crystal reports. Crystal reports can be quite a challenging project to implement! In a nutshell I was trying to recreate a very old crystal report that had a lot of functionality.
First I was trying to let the user decide whether to print one order or several orders, all user defined before crystal reports generates. Then send that data to the report using code. This would allow the user to print essentially what was several different reports with once button click.
Somewhere between starting and now you have to make sure you connect to your datasource. In my case is was a SQL database. This gave me a lot of problems! Perhaps due to having to use a very old sqlserv32.dll because of our old ERP software. I used a OLE DB Connection, Selected SQL Server Native Client 10.0 (For SQL server 2008). Then I had to install both a Crystal Runtime 32bit and Crystal Runtime 64bit and sqlncli.msi on every client, which allowed crystal reports to run on client workstations.
My code to send a parameter to crystal reports.
string OrderList = "";
OrderList += "18528-7" + ",";
OrderList += "18527-2" + ",";
OrderList += "18532-2" + ",";
Etc..Which can be accomplished better with a loop, just done this way for testing purposes.
//Set Crystal Report Parameter. This parameter must be created in crystal reports designer with the same name. The parameter type must match your code type, ie a string.
CrystalReport11.SetParameterValue("@MyCrystalReportParameter", OrderList);
In Crystal Reports (CR) to accept the multi value parameter I used Select Expert. I used my Order SQL field and used the formula:
{MySQLTable.MySQLField} in split({?@MyCrystalReportParameter}, ",")
Within CR you have to create a group for the parameter you sent and want to create multiple reports for. The groups will allow a new report to be tacked on to the end of the last report for every value you pass, in my case it was Orders. This gives you Page Headers and Report Bodies with different data for every new value (my order number).
In CR I then used Group Expert and created a Group. The Group was set as my SQL Order Field.
To have resetting Page Numbers for each distinct Order Report I Suppressed the following sections: Report Header, Group Header, Details Section, Report Footer, Page Footer. I used Page Header for My Report Headers. I used Group Footer for my various sections, inserting Additional Group Footers as needed. These contained my various sections and SubReports which displayed tables of additional data such as shipment lists, parts lists, etc.
In Group Expert for my Group By Orders Database Field I checked New Page after 1 Visible Group and Repeat Group Header on Each Page.
In Section Expert On the Last Group Footer on the Paging Tab I selected Reset Page Number After. Checking Keep together on the Common Tab might be important as well.
For each SubReport which contained essentially my dynamic data tables that would grow depending on the number of data rows in my database. I right clicked on the SubReport and selected SubReport Links, selected the field and added it to Field(s) to link to. Selected it in both drop downs below and made sure Select data in SubReprot based on field was checked. In my SubReport I had to create a group to order my data in a certain way, but suppressed the groups sections and just used ReportHeader and Detail Sections.