我用datagrid 显示vfp表格中的数据
报 [microsoft][ODBC Visual FoxPro Driver]Invalid book 这个错误我的代码如下? Dim cnDBF As ADODB.Connection
Dim cnRST As New ADODB.Recordset
Dim strConString As String
Dim strPath As String
Dim strSql As String
On Error GoTo Errorhandle
' strFile = FullFileName
strFile = "c:\cbjxz.dbf"
If InStr(strFile, "\") > 0 Then
strPath = Left(strFile, InStrRev(strFile, "\", -1, vbTextCompare) - 1)
Else
Exit Sub
End If strConString = "Driver={Microsoft Visual FoxPro Driver};" & _
"SourceType=DBF;" & _
"SourceDB=" & strPath & ";" & _
"Exclusive=YES;"
Set cnDBF = New ADODB.Connection
cnDBF.ConnectionString = strConString
cnDBF.Open strConString
cnRST.Open "select * from [cbjxz.dbf] ", cnDBF, adOpenKeyset
a=cnrst.recordcount '---------能够读出CNRST的记录数
Set DataGrid1.DataSource = cnRST ‘---------出错点,报错如上所述 Exit Sub
Errorhandle:
Set cnDBF = Nothing
Err.Raise Err.Number, Err.Source, Err.DescriptionEnd Sub
报 [microsoft][ODBC Visual FoxPro Driver]Invalid book 这个错误我的代码如下? Dim cnDBF As ADODB.Connection
Dim cnRST As New ADODB.Recordset
Dim strConString As String
Dim strPath As String
Dim strSql As String
On Error GoTo Errorhandle
' strFile = FullFileName
strFile = "c:\cbjxz.dbf"
If InStr(strFile, "\") > 0 Then
strPath = Left(strFile, InStrRev(strFile, "\", -1, vbTextCompare) - 1)
Else
Exit Sub
End If strConString = "Driver={Microsoft Visual FoxPro Driver};" & _
"SourceType=DBF;" & _
"SourceDB=" & strPath & ";" & _
"Exclusive=YES;"
Set cnDBF = New ADODB.Connection
cnDBF.ConnectionString = strConString
cnDBF.Open strConString
cnRST.Open "select * from [cbjxz.dbf] ", cnDBF, adOpenKeyset
a=cnrst.recordcount '---------能够读出CNRST的记录数
Set DataGrid1.DataSource = cnRST ‘---------出错点,报错如上所述 Exit Sub
Errorhandle:
Set cnDBF = Nothing
Err.Raise Err.Number, Err.Source, Err.DescriptionEnd Sub
试试下面的打开方式,是否可以通过
cnRST.Open strSQl, cn, adOpenStatic, adLockReadOnly
cnRST.Open strSQl, cn, 1,1
试试
试试手动连接ODBC看看!