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

标签 c# winforms c#-4.0 rdlc

我想在 RDLC 报告的文本框中显示一些值。 以下是抛出错误“本地报告处理期间发生错误”的代码。 我也上传我的表格

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();

enter image description here

最佳答案

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

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

要找出错误,请将您的代码放在 try{}catch(Exception ex){} block 中,然后查看 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 );
}

关于c# - 将参数从文本框传递到 RDLC 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33398672/

相关文章:

c#在txt文件中搜索字符串

c# - 如何匹配第一个单词?

wpf - 使用 WindowsFormsHost 托管控件的 ElementHost 托管 WPF View 的键盘焦点导航问题

c# - .NET 会受益于 "named anonymous"类型吗?

c#-4.0 - Windows Azure 模拟器 "Invalid access to memory location."

C# 按特定属性比较两个大型项目列表

c# - 如何使用 Selenium WebDriver 和 C# 单击复选框

c# - EF Core 无法连接到服务器 - 与网络相关或特定于实例的错误

c# - 数据绑定(bind)和跨线程异常

html - 如何在 winform 设计中使用 html 和/或 css?