简体   繁体   English

c#winforms本地报表处理时出错

[英]An error occurred during local report processing in c# winforms

I want to generate RDLC Report on the basis of date.我想根据日期生成RDLC Report I have two DateTimePickers and a Button Controls on my WindowForm and a ReportViewer .我的WindowFormReportViewer上有两个DateTimePickers和一个Button控件。 I select from and To Date from DateTimePicker and When I click on a Button the ReportViewer should load from Database on the basis of Date .我从DateTimePicker选择和到Date ,当我点击一个ButtonReportViewer应该基于DateDatabase加载。

Here is my Stored Procedure这是我的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

and my C# code和我的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;
    }

I have passed two parameters in fromDate and toDate in ReportViewer .我在ReportViewer中的fromDatetoDate中传递了两个参数。 When i put my program in a debug mood , and check the program and works fine ie DataTable returns values correctly but when it reach to SQL Parameters it throws an exception An error occurred during local report processing .当我将程序置于debug mood ,并检查程序并正常工作时,即DataTable正确返回值,但当它到达SQL Parameters它抛出exception An error occurred during local report processing I don't know why because my Report is in the root directory .I am also going to attach the snapshots.我不知道为什么,因为我的Reportroot directory 。我也准备附上快照。 Please help me out.请帮帮我。

在此处输入图片说明 在此处输入图片说明

Updated更新

This is my DataSet which takes two parameters这是我DataSet这需要两个参数

在此处输入图片说明

and this is Report Data这是Report Data

在此处输入图片说明

and this is the Exception Detail这是Exception Detail

在此处输入图片说明

The error is because the following statement错误是因为下面的语句

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

The parameters must be written as they are in the stored procedure and you have take into consideration capital letters and small letters.参数必须按照它们在存储过程中的方式编写,并且您已经考虑了大写字母和小写字母。 The parameters should be as the following:参数应如下所示:

FromDate从日期

ToDate迄今为止

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 本地报告处理期间发生错误 - C#Windows窗体VS2010 - An error occurred during local report processing - C# Windows Form VS2010 本地报表处理期间发生错误-SSDT - An error occurred during local report processing - SSDT RDLC报告获取错误本地报告处理期间发生错误 - RDLC report getting error An error occurred during local report processing 本地报告处理期间发生错误。 LocalReport rdlc - An error occurred during local report processing. LocalReport rdlc 安装到其他计算机后,在C#中的本地报表处理期间发生错误 - Error occured during local report processing in C# after installing to other computer 处理本地报告时发生错误 - An Error occurred while local report processing 首次使用savefiledialog保存文件后,“本地报告处理期间发生错误” - “An error occurred during local report processing” after save file at first time by using savefiledialog 本地报表处理期间发生错误 - An Error Occured During Local report Processing c#中的错误:命令处理期间发生一个或多个错误消息 - error in c# :One Or More Error Messages Occurred During Processing Of Command 打印不带预览的本地报告-流大小超出或GDI + C#中发生一般错误 - Printing a Local Report without Preview - Stream size exceeded or A generic error occurred in GDI+ C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM