大家好,我这里有这段代码
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,为什么我的报告会在> =查询中返回两个日期?
答案 0 :(得分:1)
尝试使用datediff以获得更高的精确度。用单引号包装输入值[test]。
SqlCommand cmd = new SqlCommand("SELECT DeptNo,DeptSales,DeptCustomers FROM StoreSalesDetail where DeptNo="+dept+" and datediff(d, '" + test + "', ProcDate) >=0", con);