0

我有一个项目,该项目由一个 asp.net 网页组成,该网页生成一个 pertcular 项目每天的总使用量报告。该代码使用 VS 2008 在 CR 9 中工作,但由于我使用 VS 2010 将其转换为 CR 13,因此每当我向报告中添加参数时,报告都会抛出错误为“缺少参数值”。该参数在子报表中。报告在没有参数的情况下正确可见。[dt2 有记录,我已在上述代码上方填写] 我只在星期六尝试它,我编写的代码如下所示 -

crReport cr = new crReport();
cr.SetDatabaseLogon(gf.databaseUsername, gf.databasePass);
((ReportDocument)cr.Subreports["MenuReport"]).SetDataSource(dt2);
#region Parameter gathering
ParameterValues paramQuantity = new ParameterValues();
for (int i = 0; i < dt.Rows.Count; i++)
{
    dt2.Rows[i]["menuItemFK"] = jobBll.GetDataInfo("M_MenuItems", "id", dt.Rows[i]["menuItemFK"].ToString(), "menuItemName", true);
    string menuItemFK = dt.Rows[i]["menuItemFK"].ToString();
    string reportDate = dt.Rows[i]["reportDate"].ToString();
    DataTable dtQuntity = new DataTable();
    dtQuntity = jobBll.GetMenuItemDayUsage(menuItemFK, reportFrom, reportTo, "Saturday", true);
    ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
    if (dtQuntity.Rows[0][0].ToString() != "")
        parameterDiscreteValue.Value = dtQuntity.Rows[0][0].ToString();
    else
        parameterDiscreteValue.Value = "0";
    paramQuantity.Add(parameterDiscreteValue);
}
#endregion
//cr.SetParameterValue("Sunday Quantity", paramQuantity, "MenuReport");
//cr.SetParameterValue("Monday Quantity", paramQuantity, "MenuReport");
//cr.SetParameterValue("Tuesday Quantity", paramQuantity, "MenuReport");
//cr.SetParameterValue("Wednesday Quantity", paramQuantity, "MenuReport");
//cr.SetParameterValue("Thursday Quantity", paramQuantity, "MenuReport");
//cr.SetParameterValue("Friday Quantity", paramQuantity, "MenuReport");
cr.SetParameterValue("saturdayQuantity", paramQuantity, "MenuReport");
crvReport.ReportSource = cr;     
crvReport.RefreshReport();

请尽快帮助我。等待回复。谢谢。

4

1 回答 1

1

好的,我终于开始工作了。我将“cr”声明为“ReportDocument”对象,或者“crReport.rpt”对象也注释了 cr.RefreshReport();,它正在清除参数值。现在它工作正常。为了显示记录的单个参数值,我为参数编写了“显示字符串”公式 -

StringVar Array Input:={?saturdayQuantity};
Input[RecordNumber];

现在 C# 代码如下所示 -

ReportDocument cr = new ReportDocument();//
string reportPath = Server.MapPath("crReport.rpt");//
cr.Load(reportPath);//

((TextObject)cr.ReportDefinition.ReportObjects["reportFrom"]).Text = reportFrom;
((TextObject)cr.ReportDefinition.ReportObjects["reportTo"]).Text = reportTo;
cr.SetDatabaseLogon(gf.databaseUsername, gf.databasePass);

#region Parameter gathering
ParameterValues paramQuantity = new ParameterValues();
for (int i = 0; i < dt.Rows.Count; i++)
    {
        dt2.Rows[i]["menuItemFK"] = jobBll.GetDataInfo("M_MenuItems", "id", dt.Rows[i]["menuItemFK"].ToString(), "menuItemName", true);


        //GET OPENING & CLOSING STOCK TOTAL & ASSIGN BELOW
        string menuItemFK = dt.Rows[i]["menuItemFK"].ToString();
        string reportDate = dt.Rows[i]["reportDate"].ToString();

        DataTable dtQuntity = new DataTable();
        dtQuntity = jobBll.GetMenuItemDayUsage(menuItemFK, reportFrom, reportTo, "Saturday", true);

        ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
        if (dtQuntity.Rows[0][0].ToString() != "")
            parameterDiscreteValue.Value = dtQuntity.Rows[0][0].ToString();
        else
            parameterDiscreteValue.Value = "0";

        paramQuantity.Add(parameterDiscreteValue);

    }

    cr.Subreports["MenuReport"].SetDataSource(dt2);

    ////cr.SetParameterValue("Sunday Quantity", paramQuantity, "MenuReport");
    ////cr.SetParameterValue("Monday Quantity", paramQuantity, "MenuReport");
    ////cr.SetParameterValue("Tuesday Quantity", paramQuantity, "MenuReport");
    ////cr.SetParameterValue("Wednesday Quantity", paramQuantity, "MenuReport");
    ////cr.SetParameterValue("Thursday Quantity", paramQuantity, "MenuReport");
    ////cr.SetParameterValue("Friday Quantity", paramQuantity, "MenuReport");
    cr.SetParameterValue("saturdayQuantity", paramQuantity, "MenuReport");

    ////cr.SetParameterValue("Sunday Rate", paramQuantity, "MenuReport");
    ////cr.SetParameterValue("Monday Rate", paramQuantity, "MenuReport");
    ////cr.SetParameterValue("Tuesday Rate", paramQuantity, "MenuReport");
    ////cr.SetParameterValue("Wednesday Rate", paramQuantity, "MenuReport");
    ////cr.SetParameterValue("Thursday Rate", paramQuantity, "MenuReport");
    ////cr.SetParameterValue("Friday Rate", paramQuantity, "MenuReport");
    ////cr.SetParameterValue("Saturday Rate", paramQuantity, "MenuReport");
    #endregion


    crvReport.ReportSource = cr;
    //crvReport.RefreshReport();//

我在行尾用 // 标记了编辑后的代码。

于 2012-07-02T07:30:16.993 回答