vb连接上DBC数据库后,求一SQL语句,怎么选出符合条件的时间数据?????????在线等ING

glc20022003 2006-01-20 03:31:01
MAIN.DBF库中:
CDATE BAR
2003-06-15 3194
2003-06-15 3194
2004-05-17 11543
2004-05-21 11543
. .
. .
. .
我想选择>2003-06-15的所有记录,找高手来解决!!!!!!
程序如下:
Option Explicit
Dim strpath As String
Dim datetime As Date


Private Sub Form_Load()

strpath = "Provider=MSDASQL.1;Persist Security Info=False;DSN=main;UID=;"
strpath = strpath + "SourceDB=D:\3000\TEST\数据1.dbc;SourceType=DBC;Exclusive=No;"
strpath = strpath + "BackgroundFetch=Yes;Collate=Machine;"

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
conn.ConnectionString = strpath
conn.Open


Dim sqlcmd As New ADODB.Command
sqlcmd.ActiveConnection = conn.ConnectionString


datetime = "2003-06-15"
sql = "select * from main where cdate>'应该怎么写啊'" ←这边SQL语句出错
rs.Open sql, conn, adOpenStatic, adLockReadOnly
msgbox rs.recordcount
rs.Close
conn.Close
End Sub
...全文
65 点赞 收藏 8
写回复
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
faysky2 2006-01-24

一般dbf的查询要写上.dbf,在main后面加上.dbf试试

datetime =CDate("2003-06-15")
sql = "select * from main.dbf where [cdate]>'" & datetime & "'"
回复
zou19820704 2006-01-24
最好把2003-06-15 改为 #2003-06-15# 这样的格式!!!
回复
glc20022003 2006-01-20
错误提示为:[Microsoft][ODBC Visual FoxPro Driver]Operator/operand type mismatch
回复
glc20022003 2006-01-20
还是报错,我读的是dbf的数据库,用的foxpro驱动
回复
faysky2 2006-01-20
如果你的表里设置cdate为日期类型,那得转换一下类型:

datetime =CDate("2003-06-15")
sql = "select * from main where [cdate]>'" & datetime & "'"
回复
faysky2 2006-01-20
datetime = "2003-06-15"
sql = "select * from main where [cdate]>'" & datetime & "'"
回复
glc20022003 2006-01-20
错误提示为:[Microsoft][ODBC Visual FoxPro Driver]Operator/operand type mismatch
回复
glc20022003 2006-01-20
数据库连接都正确的
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7450

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告