vb 中 提取SQL日期段数据

来源:百度知道 编辑:UC知道 时间:2024/05/16 09:46:13
在SQL 的数据库中
表DNote
列DN_date 为 datetime 的数据类型 格式:2007-7-12-星期四 上午 7:46:00
我用
Adodc1.RecordSource = "select * from DNote where DN_date between #" & DTPicker1 & "# and #" & DTPicker2 & "# "

总是提示 "列名'#200'无效
请各位高手帮帮忙
我是编程菜鸟~~可以尽量些详细点就太感谢了
DTPicker1 .value 格式为 2007-8-9-星期四
DTPicker1的format属性为 3-dtpCustom
在SQL 的数据库中
表DNote
列DN_date 为 datetime 的数据类型 与 DTPicker 不同
所以有问题的
请问DTPicker怎样转换 日期时间 格式啊
谢谢各位

要把这两个
DTPicker2
DTPicker1
的值转换为日期时间型

怎么还有星期? 把星期去了只要2007/08/09 不可以吗?

或者改成下面这样

"select * from DNote where DN_date between #" & Format(DTPicker1, "YYYY/MM/DD") & "# and #" & Format(DTPicker2, "YYYY/MM/DD") & "# "

'给你一个函数转换:
'调用方法: FormatDate(DTPicker1.Value)

Function FormatDate(byval ParDate As Date) As Date
FormatDate=Format(ParDate,"yyyy-MM-dd")
End Function

sqlserver 中 日期不是用 "#" 包围的,access用#,sqlServer用单引号
Adodc1.RecordSource = "select * from DNote where DN_date between '" & DTPicker1 & "' and '" & DTPicker2 & "' "

你还是把sql语句中between后的#改成单引号'吧