【问题标题】:An error occurred during local report processing in c# winformsc#winforms处理本地报表时出错
【发布时间】:2017-01-19 19:10:33
【问题描述】:

我想根据日期生成RDLC Report。我的WindowFormReportViewer 上有两个DateTimePickers 和一个Button 控件。我从DateTimePicker中选择和到Date,当我点击Button时,ReportViewer应该在Date的基础上从Database加载。

这是我的Stored Procedure

CREATE PROCEDURE spGetBikeSalebyDate
(
    @FromDate   DateTime,
    @ToDate     DateTime
)
AS
    BEGIN
        SELECT * FROM tblSaleBike 
        WHERE DateOfPurchase BETWEEN @FromDate AND @ToDate
        ORDER BY DateOfPurchase asc
    END

还有我的C# 代码

        private void btnSearchBikeSale_Click(object sender, EventArgs e)
    {
        ShowReport();
    }

    private void ShowReport()
    {
        reportViewer1.Reset();
        DataTable dt = GetData(dtpSearchFromDate.Value.Date, dtpSearchToDate.Value.Date);
        ReportDataSource rds = new ReportDataSource("DataSet1", dt);
        reportViewer1.LocalReport.DataSources.Add(rds);
        reportViewer1.LocalReport.ReportPath = @"ReportSaleBikeByDate.rdlc";
        ReportParameter[] rParams = new ReportParameter[] {
            new ReportParameter("fromDate",dtpSearchFromDate.Value.Date.ToShortDateString()),
            new ReportParameter("toDate",dtpSearchToDate.Value.Date.ToShortDateString())
        };
        reportViewer1.LocalReport.SetParameters(rParams);//Error Occured Here
        reportViewer1.LocalReport.Refresh();
    }

    private DataTable GetData(DateTime fromDate , DateTime toDate)
    {
        DataTable dt = new System.Data.DataTable();
        using (SqlConnection con = new SqlConnection(CS))
        {
            SqlCommand cmd = new SqlCommand("spGetBikeSalebyDate",con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add("@FromDate", SqlDbType.DateTime).Value = fromDate;
            cmd.Parameters.Add("@ToDate", SqlDbType.DateTime).Value = toDate;
            SqlDataAdapter ad = new SqlDataAdapter(cmd);
            ad.Fill(dt);
        }
        return dt;
    }

我在fromDatetoDate 中传递了两个参数ReportViewer。当我将我的程序放入debug mood 并检查程序并且工作正常时,即DataTable 正确返回值,但是当它到达SQL Parameters 时,它会抛出exception An error occurred during local report processing。我不知道为什么,因为我的Reportroot directory 中。我还要附上快照。请帮帮我。

更新

这是我的DataSet,它有两个参数

这是Report Data

这是Exception Detail

【问题讨论】:

  • 您需要分享异常详情。
  • 尊敬的先生,我更新了我的问题。我应该分享哪些细节?
  • 详细内部异常,帮你解决问题。
  • 谢谢先生,问题现已解决.. reportViewer1.localReport.Refresh 的问题。我已经删除了LocalReport,它为我解决了..

标签: c# winforms reporting rdlc


【解决方案1】:

错误是因为下面的语句

        new ReportParameter("fromDate",dtpSearchFromDate.Value.Date.ToShortDateString()),
        new ReportParameter("toDate",dtpSearchToDate.Value.Date.ToShortDateString())

参数必须按照存储过程中的方式编写,并且您已考虑到大写字母和小写字母。参数应如下:

从日期

截止日期

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-23
    • 1970-01-01
    相关资源
    最近更新 更多