Pass Perameter from textbox to RDLC report

白昼怎懂夜的黑 提交于 2019-12-24 01:30:11

问题


I want to display some values from textboxes on RDLC report. following is the code which throw an error 'An error occurred during local report processing.' i also upload my form

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


回答1:


In such cases you should put your code in a try/catch block and look at Exception and InnerExcception.

Probably you have error in assigning values, for example passing empty or null value to a parameter that is not allowed to be null or empty or a type mismatch.

To figure out the error, put your code in a try{}catch(Exception ex){} block and see ex.InnerException.Message it will show you to the main error.

Then to fix the problem, go to your report designer and make the parameter accept null and empty values or provide a suitable value for that parameter.

For example:

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


来源:https://stackoverflow.com/questions/33398672/pass-perameter-from-textbox-to-rdlc-report

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!