dateTimePicker查询时间段

private void btnSearch_Click(object sender, EventArgs e)
        {

            string startTime = dtpStart.Value.Date.ToString("yyyy-MM-dd");
            string endTime = dtpEnd.Value.Date.ToString("yyyy-MM-dd");

            string strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\Moneycounts.mdb;Persist Security Info=True";
            OleDbConnection OleCn = new OleDbConnection(strCn);
            string strCmd = "SELECT Sum(字段1) AS 表达式1 FROM Moneycounts WHERE 时间 Between (#" + startTime + "#) And (#" + endTime + "#)";
            OleDbCommand OleCmd = new OleDbCommand(strCmd, OleCn);
            DataSet dataSet = new DataSet();
            OleDbDataAdapter OleAda = new OleDbDataAdapter(OleCmd);
            //DataTable ds = new DataTable();
            OleCn.Open();
            OleAda.Fill(dataSet, "s");
            this.dgvTimeBetween.DataSource = dataSet;
            this.dgvTimeBetween.DataMember = "s";
            this.dgvTimeBetween.Rows[0].DefaultCellStyle.ForeColor = Color.Red;
            OleCn.Close();
            //MessageBox.Show(endTime);

        }

你可能感兴趣的:(datetimepicker)