簡體   English   中英

將參數從文本框傳遞到 RDLC 報告

[英]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 塊中並查看ExceptionInnerExcception

您可能在分配值時出錯,例如將空值或空值傳遞給不允許為空或空或類型不匹配的參數。

要找出錯誤,請將您的代碼放在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM