首页 文章

在水晶报告中传递多个值

提问于
浏览
0

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

到目前为止我有这个代码

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;

上面的代码是在水晶报表生成页面中,当我尝试将@Date值传递给存储过程时问题就出现了 . 存储过程运行良好,但我在C#中收到此错误

索引无效 . (HRESULT异常:0x8002000B(DISP_E_BADINDEX))

任何帮助我如何传递2个参数值?

2 回答

  • 0

    我用过不同的方法 . 如果您创建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#中就足够了)来为报告创建类 .

  • 0

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

相关问题