Report viewer set Parameters iList parameters erro

2019-09-08 11:43发布

问题:

Morning all,

Using Visual Studio 2012 Ultimate and C#.NET 4.0.

IList<Microsoft.Reporting.WinForms.ReportParameter> param = new List<Microsoft.Reporting.WinForms.ReportParameter>();

param = repsetup.NewReportSetup(
    txtNewPart.Text.ToString(),
    txtBatch.Text.ToString(), 
    txtLocation.Text.ToString(), 
    txtWheel.Text.ToString(), 
    txtGear.Text.ToString(), 
    txtLength.Text.ToString(),
    txtFits.Text.ToString(), 
    txtNewBar.Text.ToString(), 
    txtNewBarNum.Text.ToString(), 
    txtABS.Text.ToString()
);

reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter(param));

When trying to set the report parameters it complains about the list. The list is populated in another table and returns a list.

Error 2 - Argument 1: cannot convert from 'System.Collections.Generic.IList<Microsoft.Reporting.WinForms.ReportParameter>' to 'string'

Also error:

Error 1 - The best overloaded method match for 'Microsoft.Reporting.WinForms.ReportParameter.ReportParameter(string)' has some invalid arguments

How do I use the IList in the SetParameters method?

Many Thanks

Here's the NewReportSetup method:

public IList<Microsoft.Reporting.WinForms.ReportParameter> NewReportSetup(string part, string batch, string locn, string wheel, string gear, string length,
                                string fits, string newbar, string newbarnum, string abs)
{
    IList<Microsoft.Reporting.WinForms.ReportParameter> parameters = new List<Microsoft.Reporting.WinForms.ReportParameter>();
    parameters.Add( new Microsoft.Reporting.WinForms.ReportParameter("paramPart", part));
    parameters.Add( new Microsoft.Reporting.WinForms.ReportParameter("paramBatch", batch));
    parameters.Add( new Microsoft.Reporting.WinForms.ReportParameter("paramLocn", locn));
    parameters.Add( new Microsoft.Reporting.WinForms.ReportParameter("paramWheel", wheel));
    parameters.Add( new Microsoft.Reporting.WinForms.ReportParameter("paramGear", gear));
    parameters.Add( new Microsoft.Reporting.WinForms.ReportParameter("paramLength", length));
    parameters.Add( new Microsoft.Reporting.WinForms.ReportParameter("paramABS", abs));
    parameters.Add( new Microsoft.Reporting.WinForms.ReportParameter("paramBuyer", fits));
    parameters.Add( new Microsoft.Reporting.WinForms.ReportParameter("paramBarCode", newbar));
    parameters.Add( new Microsoft.Reporting.WinForms.ReportParameter("paramBartxt", newbarnum));
    return parameters;
}

回答1:

The Report.SetParameters method requires an IEnumerable<ReportParameter>:

In other words send your list of report parameters to this method, not an instance of a ReportParameter (which you're trying to create from your list):

reportViewer1.LocalReport.SetParameters(param);