You don't need to pass date parameters to report viewer , instead use those parameters as filter in your SQL query to filter the date and then populate data table for that output
finally attach that data table as data source to your report viewer
here is the sample code I tried
Date1 and Date2 are parameter object (text box or calendar objects on form)
private void Form1_Load(object sender, EventArgs e)
{
Customers dsCustomers = GetData();
ReportDataSource datasource = new ReportDataSource("Customers", dsCustomers.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(datasource);
this.reportViewer1.RefreshReport();
}
private Customers GetData()
{
string constr = @"Data Source=.\Sql2005;Initial Catalog=Northwind;Integrated Security = true";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 20 * FROM customers where Transdate between @Date1 AND @Date2"))
{
cmd.Parameters.AddWithValue("@Date1", Date1.Value);
cmd.Parameters.AddWithValue("@Date2", Date2.Value);
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (Customers dsCustomers = new Customers())
{
sda.Fill(dsCustomers, "DataTable1");
return dsCustomers;
}
}
}
}
}