C#使用两个dateTimePicker查询access数据库一段时间内的数据时查询语句出错。
首先,我Access数据库的连接是没有问题的,表名是payment,其中字段DateTime在payment表中数据类型是日期/时间,但查询语句老是有问题我试用了以下查询语句都不成功。求高手解答!
string createdb = "select * from payment where between '" + dateTimePicker3.Text + "' and '" + dateTimePicker4.Text + "'";
string createdb = "select * from payment where DateTime>= '" + dateTimePicker3.Text + "' and DateTime<='" + dateTimePicker4.Text + "'";
string createdb = "select * from payment where DateTime>= '" + dateTimePicker3.Value+ "' and DateTime<='" + dateTimePicker4.Value + "'";
string createdb = "select * from payment where between '" + dateTimePicker3.Value.ToString("yyyy/mm/dd")+ "' and '" + dateTimePicker4.Value.ToString("yyyy/mm/dd") + "'";
C#?
dateTimePicker?
数据库
SQL语句
------解决方案--------------------access数据库查日期,要加上#在日期前后
------解决方案--------------------string createdb = "select * from payment where DateTime between #" + dateTimePicker3.Value.ToString("yyyy-MM-dd 00:00:00")+ "# and #" + dateTimePicker4.Value.ToString("yyyy-MM-dd 23:59:59") + "#";