如何使用vb6.0在ms-access数据库的两个日期之间找到Recods [英] How to find Recods between two dates of ms-access database using vb6.0

查看:118
本文介绍了如何使用vb6.0在ms-access数据库的两个日期之间找到Recods的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码我写的它被执行但我不会看到数据报告的结果





rs.OpenSELECT * FROM tblwith WHERE(((datee)介于#&DOR&#和#&DTPicker1&#)),con,adOpenForwardOnly,adLockReadOnly

























plz帮帮我

解决方案

SQL可以执行,但它可能不是您想要或期望的SQL。你需要看看正在运行的是什么。建议你将SQL分解为一个单独的变量,在fetch上放置一个断点并查看发送给DB的内容。



  dim  queryString  as   string  =   SELECT * FROM tblwith WHERE(((datee)介于#& DOR&  #和#& DTPicker1&  #)) 
' 在下一行放置一个断点,运行代码并查看queryString
'
rs.Open queryString,con,adOpenForwardOnly,adLockReadOnly





日期总是很棘手。您需要确保客户端计算机和它正在通信的任何数据库没有使用不同的日期格式,特别是如果您将它们作为字符串处理。例如,2013年10月2日。在英国,即2月10日在美国,它是10月2日和2013年2月13日可能会导致美国格式环境出错,但在英国设置中不会出现任何问题。


你必须使用不同格式的MSACCESS使用VB6

喜欢

SELECT * FROM tblwith WHERE(((datee)Between'# &DOR&#'和'#&DTPicker1&#'))


试试这个。



 SELECT * FROM tblwith WHERE(datee)介于CDate('& DOR&')和CDate('& DTPicker1&')





或试试这个



 SELECT * FROM tblwith WHERE(datee)> = CDate('& DOR&')和(datee)< = CDate('& DTPicker1&')





希望这能解决您的问题


this code i written it gets executed but i won't seen the result on data report


rs.Open "SELECT * FROM tblwith WHERE (((datee) Between # " & DOR & "# And # " & DTPicker1 & "#))", con, adOpenForwardOnly, adLockReadOnly












plz help me

解决方案

The SQL may execute, but it may not be the SQL you want or expect. You need to see what's being run. Suggest you break out the SQL into a separate variable, put a breakpoint on the fetch and have a look at what's being sent to the DB.

dim queryString as string = "SELECT * FROM tblwith WHERE (((datee) Between # " & DOR & "# And # " & DTPicker1 & "#))"
' Put a break-point on the next line, run the code and look at queryString 
' in the immediate window.
rs.Open  queryString, con, adOpenForwardOnly, adLockReadOnly



Dates are always tricksy. You need to make sure that the client machine and any DB it's talking to aren't using different date formats, especially if you're handing them around as strings. For example, 10/2/2013. In the UK that's the 10th of Feb. in the US it's the 2nd of Oct. and 13/2/2013 might very well result in an error in a US format environment but will cause no problems whatsoever in a UK setup.


you have to use different format for MSACCESS using VB6
like
SELECT * FROM tblwith WHERE (((datee) Between '"#" & DOR & "#"' And '"#" & DTPicker1 & "#"'))"


Try this.

SELECT * FROM tblwith WHERE (datee) Between CDate('" & DOR & "') And CDate('" & DTPicker1 & "')



OR Try this

SELECT * FROM tblwith WHERE (datee) >= CDate('" & DOR & "') And (datee) <= CDate('" & DTPicker1 & "')



Hope this will solve your problem


这篇关于如何使用vb6.0在ms-access数据库的两个日期之间找到Recods的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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