“条件表达式中的数据类型不匹配。”在两个日期之间选择数据

时间:2018-10-16 03:52:39

标签: c#

我正在尝试选择两个日期之间的数据,但是我仍然收到“条件表达式中的数据类型不匹配”的信息。错误。该如何解决?

        string startdate;
        string enddate;

        startdate = dateTimePicker1.Value.ToString("dd/MM/yyyy");
        enddate = dateTimePicker2.Value.ToString("dd/MM/yyyy");


        int i = 0;
        OleDbCommand cmd = connection.CreateCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "select * from Sales where Date>='"+ startdate.ToString() +"' AND Date<='"+ enddate.ToString() +"'";
        cmd.ExecuteNonQuery();
        DataTable dt = new DataTable();
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        da.Fill(dt);
        dataGridView1.DataSource = dt;

        foreach (DataRow dr in dt.Rows)
        {

            i = i + Convert.ToInt32(dr["Total"].ToString());

        }

        txttotalsales.Text = i.ToString();

0 个答案:

没有答案