问题描述
我有两个表一个表包含产品信息,另一个表包含日期信息。我想从日期选择器的选定日期使用这两个表生成水晶报告。我可以生成没有日期范围的报告。
所以如何将这两个日期参数传递给我的crystalreportviewer。
什么我试过了:
private ProductSell Getdata()
{
DateTime sdt = dateTimePicker1 .Value.Date;
DateTime edt = dateTimePicker2.Value.Date;
SqlConnection connection = new SqlConnection(cn);
SqlCommand cmd = new SqlCommand(选择ProductName,sum(ProductCost)为ProductCost,Sum(ProductPrice)为ProductPrice,sum(ProductQuantity)为ProductQuantity,来自ProductSell,其中GROUP BY ProductName,连接);
// 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);
返回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();
}
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();
}
推荐答案
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);
cmd.Parameters.Add("@sdt", startDateObj);
cmd.Parameters.Add("@sdt", endDateObj);
总是使用 []
这篇关于如何将日期作为参数传递给crystal reportviewer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!