Pergunta

im pretty new to the whole ADODB stuff. I wrote a code trying to count the columns in use with this specific database. But somehow I get the follow error:

Run-time error '-2147217900 (80040e14)': Syntax error

I've tried several methods to read these columns however I can't get this done. Can somebody give me a clue how to fix this? Thanks in advance :)

 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
Foi útil?

Solução

This

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"

in the end is only the third line so your sConnection string is actually only

"Provider=VfpOleDB.1;Data Source=" & pPath & ";Collating Sequence=MACHINE;Exclusive=ON"

You have to keep adding bits (concatenating) to your connection string ie

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"
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top