I'm using Crystal Reports inside of Visual Studio 2010 with ASP.NET.
I've got a DataSet that pulls data from a database, and it seems to load into the report just fine. When I view the report in my browser, all records load correctly.
I have to add a parameter for the user to enter in order to filter out entries in the report. The problem is that when I add any sort of parameter to the report. If the parameter isn't on the page or being used in the selection expert, the records load fine. But as soon as I add the parameter to the page, no records can be found. In other words, if the parameter prompt is displayed, the viewer loads no records.
I added a drop down list parameter just containing the numbers 1, 2, and 3. Without anything in the selection expert this shouldn't affect anything. But for whatever reason, when this is in the report no records get selected. As soon as I remove it from the page, all records load fine.
I'm adding the parameter and its values through the field explorer if that makes a difference.
The odd thing is that is implementation worked when I had the report pull its data directly from the database, instead of creating a DataSet first. The reason I can't use this implementation is that it kept asking for the database login information. Even when I predefined the information. I switched to a DataSet so I would avoid the login prompt.
Here is the relevant code:
myDataSet ds =new myDataSet();
myDataSetTableAdapters.myTableTableAdapter dsTA =new myDataSetTableAdapters.myTableTableAdapter();
dsTA.Fill(ds.myTable);
// Initializing the report file
rpt =newReportDocument();
string reportPath =Server.MapPath(mapPath);
rpt.Load(reportPath);
Response.Write("<script>alert('DataSet has "+ ds.myTable.Rows.Count+" rows');</script>");
rpt.SetDataSource(ds);
//Response.Write("<script>alert('Report has "+ rpt.Rows.Count +" rows');</script>");
// Binding the report file to the report viewer on the page
CrystalReportViewer1.ReportSource= rpt;
The first Response.Write does indeed print the correct number of rows being sent to the report viewer. But the second one that counts the rows in the report throws a "COM Exception: Missing Parameter Values" when the parameter is on the page. Both work when the parameter isn't on the page. rpt.HasRecords also fails.
I can see this behavior when the website is being run in VS2010's debugging mode, and in the report preview within VS2010. Even without the DataSet containing any data, the report still displays the filler data when there aren't parameters on the page, and no filler data when a parameter is added.
I didn't want to have to pass in a parameter, because I want the user to be prompted for one at the start. But I did try adding one in.
rpt.SetParameterValue("par1", 1);
Interestingly, this allowed all of the data to be loaded in the viewer... until I passed it a new parameter. Then it returned no results. Even when setting it back to 1. It seems that for some reason, when the viewer is given a parameter to handle it drops all of the records.
I honestly have no idea of where to go with this now. The errors appear to either be coming from rpt.SetDataSource, CrystalReportViewer1.ReportSource.