将参数从文本框传递到 RDLC 报告

Pass Perameter from textbox to RDLC report

我想在 RDLC 报告的文本框中显示一些值。 以下是抛出错误的代码 'An error occurred during local report processing.' 我也上传了我的表格

ReportParameter param_DateFrom = new ReportParameter("DateTimePickerFrom", DatemePickerFrom.Value.Date.ToShortDateString(), false);
ReportParameter param_DateTo = new ReportParameter("DateTimePickerTo", DateTimePickerTo.Value.Date.ToShortDateString(), false);
ReportParameter paramAccountNo = new ReportParameter("AccountNo", textBoxAccountNo.Text, false);
ReportParameter paramNamefname = new ReportParameter("NameFname", textBoxName.Text, false);
ReportParameter paramAddress = new ReportParameter("Address", textBoxAddress.Text, false);
ReportParameter paramAccountType = new ReportParameter("AccounType", txtAccountType.Text, false);
ReportParameter paramOpeningBalance = new ReportParameter("OpeningBalance", textBoxOpeningBalance.Text, false);
//ReportParameter paramBankName = new ReportParameter("BankName",comboBoxBanks.SelectedText,false);

this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { param_DateFrom, param_DateTo, paramAccountNo, paramNamefname, paramAddress, paramAccountType, paramOpeningBalance});
this.reportViewer1.LocalReport.Refresh();

this.ReportBetweenDatesTableAdapter.Fill(this.DataSet1.ReportBetweenDates, Convert.ToInt32(comboBoxBanks.SelectedValue), DateTimePickerFrom.Value, DateTimePickerTo.Value);
this.reportViewer1.RefreshReport();

在这种情况下,您应该将代码放在 try/catch 块中并查看 ExceptionInnerExcception

可能是您在赋值时出错,例如将空值或 null 值传递给不允许为 null 或空值或类型不匹配的参数。

要找出错误,请将您的代码放在 try{}catch(Exception ex){} 块中,然后查看 ex.InnerException.Message 它会向您显示主要错误。

然后要解决此问题,请联系您的报表设计器并使参数接受 null 和空值或为该参数提供合适的值。

例如:

try
{
    ReportParameter param_DateFrom = new ReportParameter("DateTimePickerFrom", DateTimePickerFrom.Value.Date.ToShortDateString(), false);
    ReportParameter param_DateTo = new ReportParameter("DateTimePickerTo", DateTimePickerTo.Value.Date.ToShortDateString(), false);
    ReportParameter paramAccountNo = new ReportParameter("AccountNo", textBoxAccountNo.Text, false);
    ReportParameter paramNamefname = new ReportParameter("NameFname", textBoxName.Text, false);
    ReportParameter paramAddress = new ReportParameter("Address", textBoxAddress.Text, false);

    ReportParameter paramAccountType = new ReportParameter("AccounType", txtAccountType.Text, false);
    ReportParameter paramOpeningBalance = new ReportParameter("OpeningBalance", textBoxOpeningBalance.Text, false);
    //ReportParameter paramBankName = new ReportParameter("BankName",comboBoxBanks.SelectedText,false);

    this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { param_DateFrom, param_DateTo, paramAccountNo, paramNamefname, paramAddress, paramAccountType, paramOpeningBalance });
    this.reportViewer1.LocalReport.Refresh();
    this.ReportBetweenDatesTableAdapter.Fill(this.DataSet1.ReportBetweenDates, Convert.ToInt32(comboBoxBanks.SelectedValue), DateTimePickerFrom.Value, DateTimePickerTo.Value);
    this.reportViewer1.RefreshReport();
}
catch (Exception ex)
{
    var message = ex.Message;
    if (ex.InnerException != null)
        message += "\n" + ex.InnerException.Message;
    MessageBox.Show(message );
}