我想根据日期生成RDLC Report
。我的DateTimePickers
和Button
上有两个WindowForm
和一个ReportViewer
控件。我从Date
中选择和DateTimePicker
,当我点击Button
时ReportViewer
应根据Database
从Date
加载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
中的ReportViewer
和debug mood
传递了两个参数。当我将我的程序放入DataTable
时,检查程序并正常工作,SQL Parameters
正确返回值,但当它到达exception
时,它会抛出An error occurred during local report processing
{{1 }}。我不知道为什么,因为我的Report
位于root directory
。我还要附上快照。请帮帮我。
更新
这是我的DataSet
,它带有两个参数
这是Report Data
这是Exception Detail
答案 0 :(得分:1)
错误是因为以下声明
new ReportParameter("fromDate",dtpSearchFromDate.Value.Date.ToShortDateString()),
new ReportParameter("toDate",dtpSearchToDate.Value.Date.ToShortDateString())
参数必须按照存储过程编写,并且您已考虑大写字母和小写字母。参数应如下所示:
FROM日期
ToDate