VBA/Excel/Access/Word/Access/dBASE ADO — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 16:33, 26 мая 2010

Open dBase file and query data

 
Sub Open_dBase_DSNLess()
   Dim conn As ADODB.Connection
   Dim rst As ADODB.Recordset
   Set conn = New ADODB.Connection
   conn.Open "DRIVER={Microsoft dBase Driver (*.dbf)};" & "DBQ=" & CurrentProject.Path & "\"
   Debug.Print conn.ConnectionString
   Set rst = New ADODB.Recordset
   rst.Open "Select * From Customer.dbf", conn, adOpenStatic, adLockReadOnly, adCmdText
   Do Until rst.EOF
      Debug.Print rst.Fields(1).Value
      rst.MoveNext
   Loop
   rst.Close
   Set rst = Nothing
   conn.Close
   Set conn = Nothing
End Sub



Opening a dBASE file with ADO

 
Sub Open_dBaseFile()
   Dim conn As ADODB.Connection
   Dim rst As ADODB.Recordset
   Set conn = New ADODB.Connection
   conn.Open "Provider=MSDASQL;DSN=MyDbaseFile;"
   Set rst = New ADODB.Recordset
   rst.Open "Customer.dbf", conn, , , adCmdTable
   Do Until rst.EOF
      Debug.Print rst.Fields(1).Value
      rst.MoveNext
   Loop
   rst.Close
   Set rst = Nothing
   conn.Close
   Set conn = Nothing
End Sub