Pass multiple values in crystal report

0

I am trying to pass 2 values that are generated from C# passed to MS SQL stored procedure through Crystal reports

so far i have this code

string username = Context.User.Identity.Name;
string date = DateTime.Now.ToShortDateString() ;
ReportDocument crystalReport = new ReportDocument();

crystalReport.Load(Server.MapPath(@"..\admin\CrystalReport1.rpt"));
crystalReport.SetParameterValue("@Username", username);
crystalReport.SetParameterValue("@Date", date);

crystalReport.SetDatabaseLogon("", "", @"dennislaptop-pc\SQLEXPRESS", "healthylifestyledb");
CrystalReportViewer1.ReportSource = crystalReport;

the above code is in the crystal report generation page the problem is when i try to pass the @Date Value to the stored procedure. the stored procedure works well but i am getting this error in C#

Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))

any help how i can pass 2 parameter values ?

c#
crystal-reports
parameters
asked on Stack Overflow Apr 21, 2011 by Dennis Vella • edited Apr 21, 2011 by RvdK

2 Answers

0

I've used a different method. If you create a CrystalReport C# will generate a class (and .cs) file for that report.

You can then create the report via ReportClass report = new CrystalReport1();

Then you can add parameters:

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

ReportClass report = new CrystalReport1();
report.SetParameterValue("companies", "Microsoft");
//or use the overloaded value for an array as 2nd parameter

But you need to have your reports created via C# (or maybe added to C# is enough) to create the class for the report.

answered on Stack Overflow Apr 21, 2011 by RvdK
0

Are the parameters both from the same 'source'? For some reason, if you're trying to write to a parameter that Crystal is passing to a stored procedure, you need the @ in front of the name, while if it's a parameter that you've manually added to the report, the @ isn't needed. If '@Date' doesn't work as the name, try just 'Date'.

answered on Stack Overflow Apr 21, 2011 by MartW

User contributions licensed under CC BY-SA 3.0