[英]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.