0

大家好,我这里有这个代码

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-05-04 那么为什么我的报告在 >= 查询中返回两个日期?

4

1 回答 1

1

尝试使用 datediff 以获得更高的精度。将输入值 [test] 用单引号括起来。

SqlCommand cmd = new SqlCommand("SELECT DeptNo,DeptSales,DeptCustomers FROM StoreSalesDetail where DeptNo="+dept+" and datediff(d, '" + test + "', ProcDate) >=0", con);
于 2013-05-04T15:43:44.567 回答