如何在c#中从ms访问数据库中选择数据到今天的日期

时间:2016-06-22 21:52:36

标签: c# database date oledb

我想知道如何从今天起在C#中从MS Access数据库中选择数据。

我可以在日期之间从数据库中选择数据,但是当我今天选择日期并获取数据时,它会显示空白。

请帮帮我。这是我的代码:

private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "Today Report")
            {
                DataSet dsa = new DataSet();
                DataTable dt = new DataTable();
                dsa.Tables.Add(dt);
                OleDbDataAdapter da = new OleDbDataAdapter();
                da = new OleDbDataAdapter("SELECT [Column1],[Column2],[Column3],[Date] from [Total] Where [Date] = #" + dateTimePicker1.Value.ToString() + "#", VCON);
                da.Fill(dt);
                CrystalReport4 MYREPORT = new CrystalReport4();
                MYREPORT.SetDataSource(dt);
                crystalReportViewer1.ReportSource = MYREPORT;
                VCON.Close();
            }
            else if (textBox1.Text == "Custom Report")
            {
                DataSet dsa = new DataSet();
                DataTable dt = new DataTable();
                dsa.Tables.Add(dt);
                OleDbDataAdapter da = new OleDbDataAdapter();
                da = new OleDbDataAdapter("SELECT [Column1],[Column2],[Column3],[Date] from [Total] Where [Date] between #" + dateTimePicker2.Value.ToString() + "# AND #" + dateTimePicker3.Value.ToString() + "#", VCON);
                da.Fill(dt);
                CrystalReport4 MYREPORT = new CrystalReport4();
                MYREPORT.SetDataSource(dt);
                crystalReportViewer1.ReportSource = MYREPORT;
                VCON.Close();
            }
            else
            {
                MessageBox.Show("Sorry! File was not Found:Please Try Again", "Daily Report", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

0 个答案:

没有答案