C# 在crystal报告中传递多个值

C# 在crystal报告中传递多个值,c#,crystal-reports,parameters,C#,Crystal Reports,Parameters,我试图通过Crystal reports将C生成的2个值传递给MS SQL存储过程 到目前为止,我有这个代码 string username = Context.User.Identity.Name; string date = DateTime.Now.ToShortDateString() ; ReportDocument crystalReport = new ReportDocument(); crystalReport.Load(Server.MapPath(@"..\admin\C

我试图通过Crystal reports将C生成的2个值传递给MS SQL存储过程

到目前为止,我有这个代码

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;
上面的代码在crystal report generation页面中,问题是当我尝试将@Date值传递给存储过程时。存储过程运行良好,但我在C中遇到了这个错误

无效索引。来自HRESULT的异常:0x8002000B DISP_E_BADINDEX


有没有关于如何传递2个参数值的帮助?

我使用了不同的方法。如果创建CrystalReport,C将为该报告生成一个类和.cs文件

然后,您可以通过ReportClass report=new CrystalReport1创建报告

然后可以添加参数:

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

但是您需要通过C创建报表,或者将报表添加到C就足以为报表创建类。

这两个参数是否都来自同一个“源”?出于某种原因,如果您试图写入Crystal传递给存储过程的参数,则名称前面需要@,而如果是手动添加到报表中的参数,则不需要@。如果'@Date'不能用作名称,请尝试使用'Date'。

数据将被传递到存储过程中,因此需要@符号如果使用索引而不是名称,即..SetParameterValue1,value,是否有效?是否有包含参数的子报告?