[英]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
.我的
WindowForm
和ReportViewer
上有两个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
,当我点击一个Button
, ReportViewer
应该基于Date
从Database
加载。
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
中的fromDate
和toDate
中传递了两个参数。 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.我不知道为什么,因为我的
Report
在root 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.