[英]Pass Perameter from textbox to RDLC report
我想在 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();
在这种情况下,您应该将代码放在 try/catch 块中并查看Exception
和InnerExcception
。
您可能在分配值时出错,例如将空值或空值传递给不允许为空或空或类型不匹配的参数。
要找出错误,请将您的代码放在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 );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.