c#winforms

时间:2017-01-19 19:10:34

标签: c# winforms reporting rdlc

我想根据日期生成RDLC Report。我的DateTimePickersButton上有两个WindowForm和一个ReportViewer控件。我从Date中选择和DateTimePicker,当我点击ButtonReportViewer应根据DatabaseDate加载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; } 代码

fromDate

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

enter image description here enter image description here

更新

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

enter image description here

这是Report Data

enter image description here

这是Exception Detail

enter image description here

1 个答案:

答案 0 :(得分:1)

错误是因为以下声明

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

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

FROM日期

ToDate