开发者

How to pass parameters to crystal report?

开发者 https://www.devze.com 2023-02-16 02:26 出处:网络
crystal report has two parameters field, however, i used three method searched, all failed. Error is missing parameter values.

crystal report has two parameters field, however, i used three method searched, all failed. Error is missing parameter values.

sure parameter is passing by query string http://localhost:1604/Cheques/viewReport.aspx?type=TT&ID=5&tCOMDB=Project_TR_TP_COM_Test checked by Label

However, do not know why Error is missing parameter values.

Method 1

// First parameter
            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = Request.QueryString["ID"];
            crParameterFieldDefinitions = objRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["Cheque_IssueRecord_Secretary_Review_TT_ID"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
            // Second parameter
            ParameterFieldDefinitions crParameterFieldDefinitions2;
            ParameterFieldDefinition crParameterFieldDefinition2;
            ParameterValues crParameterValues2 = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue2 = new ParameterDiscreteValue();

            crParameterDiscreteValue2.Value = Request.QueryString["tCOMDB"];
            crParameterFieldDefinitions2 = objRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition2 = crParameterFieldDefinitions2["tCOMDB"];
            crParameterValues2 = crParameterFieldDefinition2.CurrentValues;

            crParameterValues2.Clear();
            crParameterValues2.Add(crParameterDiscreteValue2);
            crParameterFieldDefinition2.ApplyCurrentValues(crParameterValues2);

Method 2

//objRpt.SetParameterValue("Cheque_IssueRecord_Secretary_Review_TT_ID", Request.QueryString["ID"]);
            //objRpt.SetParameterValue("tCOMDB", Request.QueryString["tCOMDB"]);

Method 3

var value = new ParameterDiscreteValue();
            value.Value = Request.QueryString["ID"];
            objRpt.ParameterFields["Cheque_IssueRecord_Secretary_Review_TT_ID"].CurrentValues.Add(value);

            var value2 = new ParameterDiscreteValue();
            value2.Value = Request.QueryString["tCOMDB"];
            objRpt.ParameterFields["tCOMDB"].CurrentValues.Add(value2); 

This crystal report database use stored procedure,开发者_如何转开发 parameter field is automatically added, after added i removed @ character do not know why parameter missing


Try this:

foreach (var p in reportViewer.ParameterFieldInfo)
{
    if (QueryString.ContainsKey(p.Name))
    {
        var value = QueryString[p.Name];
        if (p.CurrentValues.Count > 0)
            ((ParameterDiscreteValue)p.CurrentValues[0]).Value = value;
        else
            p.CurrentValues.Add(new ParameterDiscreteValue() { Value = value });
    }
}

This assumes that your URL parameters have the same name than the report parameters.

Also, reportViewer is the ReportViewer object (your control in your ASPX page), not the ReportDocument


I solved

            objRpt.SetParameterValue(0, Convert.ToInt32(Request.QueryString["Cheque_IssueRecord_Secretary_Review_TT_ID"]));
            objRpt.SetParameterValue(1, Request.QueryString["tCOMDB"]);

            //The viewer's reportsource must be set to a report before any parameter fields can be accessed.
            CrystalReportViewer1.ReportSource = objRpt;

use above code and remove refresh report and setlogondatabase("user", "passwd") then succeed


Did u check whether the printview is exists in your crystal report? It takes PrintView also as a parameter. Pass value true or false for this.

0

精彩评论

暂无评论...
验证码 换一张
取 消