是SQL Server吗?
如果是,建议改成这样~~
'转换日期格式为SQL能接受的格式(月/日/年 时:分:秒)
Public Function GetSQLTimeFormat(ByVal d As Date) As String
GetSQLTimeFormat = "'" & DatePart("yyyy", d) & "-" & DatePart("m", d) & "-" & DatePart("d", d) & " " & Format(d, "HH:nn:ss") & "'"
End FunctionDim rstemp As New ADODB.Recordset
'Set rstemp = New ADODB.Recordset
Dim StartTime As Date
Dim EndTime As Date
Dim strSQl As String
StartTime = 2002 - 1 - 1
EndTime = 2002 - 12 - 31
strSQl = "select * from present where 日期 between " & GetSQLTimeFormat(StartTime) & " and " & GetSQLTimeFormat(EndTime)
rstemp.Open strSQl, gadoConnect, 1, 3
Call ShowData(rstemp)
如果是,建议改成这样~~
'转换日期格式为SQL能接受的格式(月/日/年 时:分:秒)
Public Function GetSQLTimeFormat(ByVal d As Date) As String
GetSQLTimeFormat = "'" & DatePart("yyyy", d) & "-" & DatePart("m", d) & "-" & DatePart("d", d) & " " & Format(d, "HH:nn:ss") & "'"
End FunctionDim rstemp As New ADODB.Recordset
'Set rstemp = New ADODB.Recordset
Dim StartTime As Date
Dim EndTime As Date
Dim strSQl As String
StartTime = 2002 - 1 - 1
EndTime = 2002 - 12 - 31
strSQl = "select * from present where 日期 between " & GetSQLTimeFormat(StartTime) & " and " & GetSQLTimeFormat(EndTime)
rstemp.Open strSQl, gadoConnect, 1, 3
Call ShowData(rstemp)
Access数据库:
rstemp.Open "select * from present where 日期 between #2002-1-1# and #2002-12-31#", conn, 1, 3SQL Server数据库:
rstemp.Open "select * from present where 日期 between '2002-1-1' and '2002-12-31'", conn, 1, 3
StartTime = #1/1/2002#
EndTime = #12/31/2002#
'转换日期格式为SQL能接受的格式(月/日/年 时:分:秒)
Public Function GetSQLTimeFormat(ByVal d As Date) As String
GetSQLTimeFormat = "'" & DatePart("yyyy", d) & "-" & DatePart("m", d) & "-" & DatePart("d", d)
End FunctionDim rstemp As New ADODB.Recordset
'Set rstemp = New ADODB.Recordset
Dim StartTime As Date
Dim EndTime As Date
Dim strSQl As String
StartTime = 2002 - 1 - 1
EndTime = 2002 - 12 - 31
strSQl = "select * from present where 日期 between " & GetSQLTimeFormat(StartTime) & " and " & GetSQLTimeFormat(EndTime)
rstemp.Open strSQl, gadoConnect, 1, 3
Call ShowData(rstemp)如果这样,运行的结果就是rstemp.Open "select * from present where 日期 between '2002-1-1' and '2002-12-31'", conn, 1, 3