我想在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();
答案 0 :(得分:1)
在这种情况下,您应该将代码放在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 );
}