I have two table one table contain product information and another table contain date information.I want to generate crystal report using these two tables from selected date from date picker. i am able to generate report without date range.
so how to pass those two date parameter to my crystalreportviewer.
What I have tried:
private ProductSell Getdata()
{
DateTime sdt = dateTimePicker1.Value.Date;
DateTime edt = dateTimePicker2.Value.Date;
SqlConnection connection= new SqlConnection(cn);
SqlCommand cmd = new SqlCommand("Select ProductName,sum(ProductCost)as ProductCost,Sum(ProductPrice)as ProductPrice,sum(ProductQuantity)as ProductQuantity from ProductSell Where GROUP BY ProductName", connection);
// SqlCommand cmd = new SqlCommand("SELECT ProductSell.ProductName, sum(ProductSell.ProductCost)as pc,sum(ProductSell.ProductPrice)as pp,sum(ProductSell.ProductQuantity)as pq FROM ProductSell INNER JOIN Project ON ProductSell.ProjectID = Project.ProjectID WHERE (Project.Date >='"+sdt+"') AND (Project.Date <='"+edt+"') GROUP BY ProductSell.ProductName", connection);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
ProductSell dsproductsell = new ProductSell();
sda.Fill(dsproductsell, "ProdSellDT");
return dsproductsell;
}
private void button1_Click(object sender, EventArgs e)
{
ProductSellReport psreport = new ProductSellReport();
ProductSell dsproductsell = Getdata();
psreport.SetDataSource(dsproductsell);
this.ProductSellReportViewer.ReportSource = psreport;
this.ProductSellReportViewer.RefreshReport();
}