2013-05-04 59 views
0

大家好我这里有这个代码在我的表C#报告通过查询

SqlConnection con = new SqlConnection(Properties.Settings.Default.StoreDBConnection); 
    SqlDataAdapter da = new SqlDataAdapter(); 
    private void Form1_Load(object sender, EventArgs e) 
    { 
     String test = DateTime.Now.ToString("yyyy-MM-dd"); 
     var dept = Properties.Settings.Default.GiftDepartment; 
     MessageBox.Show(""+test+""); 
     SqlCommand cmd = new SqlCommand("SELECT DeptNo,DeptSales,DeptCustomers FROM StoreSalesDetail where DeptNo="+dept+" and ProcDate>="+test+"", con); 
     SqlDataAdapter da = new SqlDataAdapter(cmd); 
     DataSet1 ds = new DataSet1(); 
     da.Fill(ds); 
     reportViewer1.LocalReport.DataSources.Clear(); 
     reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", ds.Tables[1])); 
     this.reportViewer1.RefreshReport(); 

    } 

的样本数据

2013-05-03 00:00:00.000,2,120.0000,1,1 
2013-05-04 00:00:00.000,2,50.0000,1,1 

测试返回日期2013年5月4日,为什么我的报告同时返回日期在> =查询中?

+0

在填充操作之后放置一个while循环并枚举第一个数据表中的所有行。你看到两行(试图确定这是查询/数据问题还是报告工具问题) – billinkc 2013-05-04 15:12:15

+0

你能给我一个你想让我试试的while循环的例子么? – quatre432 2013-05-04 15:17:35

回答

1

尝试使用datediff以获得更高精度。将输入值[测试]用单引号包裹。

SqlCommand cmd = new SqlCommand("SELECT DeptNo,DeptSales,DeptCustomers FROM StoreSalesDetail where DeptNo="+dept+" and datediff(d, '" + test + "', ProcDate) >=0", con); 
+0

我其实只是想通了我的promblem需要执行此操作SELECT DeptNo,DeptSales,DeptCustomers FROM StoreSalesDetail where DeptNo =“+ dept +”and ProcDate> ='“+ test +”'“,con); – quatre432 2013-05-04 15:59:09