如何在日期之间进行搜索 [英] How to Search between Dates EXACTLY

查看:76
本文介绍了如何在日期之间进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在2个日期之间搜索时出现问题,当我从date = 9/1/2014,UpTo = 9/5/2014中选择时,其工作但不是确切的日期..它显示为9/1 / 2014年9月16日。任何帮助将不胜感激



这里是我的代码




I have a problem in my searching between 2 dates, when i choose from date = 9/1/2014 , UpTo = 9/5/2014, its working but not exact dates.. it displayed 9/1/2014 to 9/16/2014. any help will appreciate Thanks

here's my code
:

Dim sqlstring As String = "SELECT * FROM Reports WHERE Dates>=CDate( ' " & From.Text & "') AND Dates<=CDate('" & UpTo.Text & "')"

           com = New OleDbCommand(sqlstring, conn)
           Dim oledbdataadapter1 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(sqlstring, conn)
           Dim myDataSet As DataSet = New DataSet()
           oledbdataadapter1.Fill(myDataSet, "Reports")
           DataGridView1.DataSource = myDataSet.Tables("Reports").DefaultView

推荐答案

这就是我要做的:



在构建SQL字符串的行之后用断点运行调试



当它中断时,查看值的值字符串,复制然后将其粘贴到SSMS中并在那里运行



正如SRS所说,它可能是你正在使用的日期字符串的格式 - 所以你可以修复很容易在SSMS中 - 看看它是否有效,然后将该更改应用于数据库或应用程序。



顺便说一句,在SQL上使用日期时,我通常使用格式'13 -Jan-2014'以避免任何混淆。
This is what I would do:

Run it in debug with a breakpoint after the line that builds the SQL string

When it breaks, look at the value of the string, copy it then paste it in SSMS and run it there

As SRS says, it is likely the format of the date strings you are using - so you can fix that in SSMS easily - see if it works, then apply that change to either the database or the application.

incidentally, when using dates on SQL, I generally use the format '13-Jan-2014' to avoid any confusion.


这篇关于如何在日期之间进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆