在两个日期之间搜索不正确 [英] between two dates not searching properly
本文介绍了在两个日期之间搜索不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想要这两个日期之间的数据,我正在使用win7
当我搜索2011年11月11日至2011年11月15日时,显示的是2011年11月11日的记录.
ss =从表名中选择*,其中expiredate> =#"& DateTimePicker1.Value.Date& #and expiredate< =#"& DateTimePicker2.Value.Date& #"
hi folks,
i want data between this two dates i am using win7
while i search 09/11/2011 to 15/11/2011,it is displaying 08/11/2011 record.
ss = "Select * from tablename where expiredate>=#" & DateTimePicker1.Value.Date & "# and expiredate<=#" & DateTimePicker2.Value.Date & "# "
推荐答案
我认为这会起作用.
I think this will work.
ss = "Select * from tablename where expiredate>=#" & DateTimePicker1.Value.Date.ToString("MM/dd/yyyy") & "# and expiredate<=#" & DateTimePicker2.Value.Date.ToString("MM/dd/yyyy") & "# "
您应该尝试并使用参数化查询而不是串联字符串.要在日期之间进行比较,您可以像这样使用SQL之间的functoin
You should try and use Parameterised queries instead of concatenating strings. To compare between dates you can use the SQL Between functoin like this
ss = "SELECT * FROM tablename WHERE expiredate BETWEEN @StartDate and @EndDate"
yourCOmmand.Parameters.AddWithValue("@StartDate", DateTimePicker1.Value.Date);
yourCOmmand.Parameters.AddWithValue("@EndDate", DateTimePicker2.Value.Date);
如果您正在使用Access数据库(不说),则可能需要使用?"参数类型,而不是命名参数.
希望对您有帮助
If you are using Access database (you don''t say) you might need to use the "?" parameter type instead of named paramters.
Hope this helps
这篇关于在两个日期之间搜索不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文