我对整个ADODB的东西都很新。我写了一个代码,试图计算这个特定数据库使用的列。但不知怎的,我得到了以下错误:
运行时错误'-2147217900(80040e14)':语法错误
我已经尝试了几种方法来阅读这些列但是我无法完成这项工作。有人能告诉我如何解决这个问题吗?在此先感谢:)
Public Function GetParameterDbfTotalColumn() As Long
Dim sConnectionString As String
Dim mdbConn As ADODB.Connection
Dim mrst As ADODB.Recordset
Dim pPath As String
Dim sTable As String
GetParameterDbfTotalColumn = -1
pPath = "C:\ProgramData\Citect\CitectSCADA 7.20\User\Huisman V4\parameters.dbf"
Set mdbConn = New ADODB.Connection
sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & pPath & ";Extended Properties=""DBASE IV;"";"
sConnectionString = "Driver={Microsoft dBase Driver (*.dbf)};DefaultDir=" & pPath & ";Extended Properties=""DBASE IV;"";DriverId=533;CollatingSequence=ASCII;Deleted=0;FIL=dBase 5.0;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Statistics=0;Threads=3;UserCommitSync=Yes;"
sConnectionString = "Provider=VfpOleDB.1;Data Source=" & pPath & ";Collating Sequence=MACHINE;Exclusive=ON"
mdbConn.Open sConnectionString
Set mrst = New ADODB.Recordset
mrst.Open sTable, mdbConn, adOpenDynamic, adLockPessimistic, adCmdTable
GetParameterDbfTotalColumn = mrst.Fields.Count
GetParameterDbfTotalColumn = 0
Exit Function
End Function
答案 0 :(得分:1)
这个
sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & pPath & ";Extended Properties=""DBASE IV;"";"
sConnectionString = "Driver={Microsoft dBase Driver (*.dbf)};DefaultDir=" & pPath & ";Extended Properties=""DBASE IV;"";DriverId=533;CollatingSequence=ASCII;Deleted=0;FIL=dBase 5.0;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Statistics=0;Threads=3;UserCommitSync=Yes;"
sConnectionString = "Provider=VfpOleDB.1;Data Source=" & pPath & ";Collating Sequence=MACHINE;Exclusive=ON"
最后只是第三行,所以你的sConnection字符串实际上只是
"Provider=VfpOleDB.1;Data Source=" & pPath & ";Collating Sequence=MACHINE;Exclusive=ON"
您必须不断向连接字符串添加位(连接),即
sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & pPath & ";Extended Properties=""DBASE IV;"";"
sConnectionString = sConnectionString & "Driver={Microsoft dBase Driver (*.dbf)};DefaultDir=" & pPath & ";Extended Properties=""DBASE IV;"";DriverId=533;CollatingSequence=ASCII;Deleted=0;FIL=dBase 5.0;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Statistics=0;Threads=3;UserCommitSync=Yes;"
sConnectionString = sConnectionString & "Provider=VfpOleDB.1;Data Source=" & pPath & ";Collating Sequence=MACHINE;Exclusive=ON"