参数未传递给asp.net C#中的crystal报表

时间:2013-02-21 05:48:23

标签: asp.net crystal-reports

我将参数化存储过程作为Crystal Report的源。我试图从代码C#后面传递它们。

我提到了很多主题,但仍然遗漏了一些内容,并且收到错误:

Failed to open a rowset.  Details:  ADO Error Code: 0x   Source: Microsoft SQL Native Client   Description: Procedure 'SP_GetProductsbySales' expects parameter '@top', which was not supplied.   SQL State: 42000   Native Error: Failed to open a rowset.   Error in File C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\TopSelling_Report {B8B4EAE6-D01E-4D18-9003-23A047F9DD5B}.rpt: Failed to open a rowset

这是我的代码:

 private void ConfigureCrystalReports()
{
    rpt = new ReportDocument();

    string reportPath = Server.MapPath("TopSelling_Report.rpt");

    CrystalReportViewer1.ParameterFieldInfo.Clear();
    ParameterFields param = CrystalReportViewer1.ParameterFieldInfo;
    ParameterField top = new ParameterField();
    top.Name = "@top";
    ParameterDiscreteValue top_val = new ParameterDiscreteValue();
    top_val.Value = 100;
    top.CurrentValues.Add(top_val);

    ParameterField all = new ParameterField();
    all.Name = "@all";
    ParameterDiscreteValue all_val = new ParameterDiscreteValue();
    all_val.Value = false;
    all.CurrentValues.Add(all_val);

    param.Add(top);
    param.Add(all);
    CrystalReportViewer1.ParameterFieldInfo = param;


    rpt.Load(reportPath);
    rpt.SetParameterValue(0, Convert.ToInt32(50));
    rpt.SetParameterValue(1, Convert.ToBoolean(false));


    ConnectionInfo connectionInfo = new ConnectionInfo();
    connectionInfo.ServerName = "xxxx";
    connectionInfo.DatabaseName = "xxxxx";
    connectionInfo.UserID = "xxx";
    connectionInfo.Password = "xxxx";
    SetDBLogonForReport(connectionInfo, rpt);
    CrystalReportViewer1.ReportSource = rpt;
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
{
    Tables tables = reportDocument.Database.Tables;
    foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
    {
        TableLogOnInfo tableLogonInfo = table.LogOnInfo;
        tableLogonInfo.ConnectionInfo = connectionInfo;
        table.ApplyLogOnInfo(tableLogonInfo);
    }
}

我试图以两种方式传递参数,但你仍然会收到错误。 我发现特别的问题,如果我删除 SetDBLogonForReport()方法,那么它工作正常。所以,如果我删除自动登录,那么它工作正常,但如果我保持它原样或修改该代码的代码,那么它将给出高于错误。

我尝试用SetDatabaseLogon()方法替换我的代码,但它仍然给了我不希望的登录提示。

我正在使用visual studio 2005。 感谢您的帮助。 感谢。

0 个答案:

没有答案