|
|
Title | Use ADO to get data from a read-only Access database |
Keywords | ADO, Access, database, connect, read-only |
Categories | Database |
|
|
In the connect string, set Mode = Read.
|
|
Dim conn As ADODB.Connection
' Open a connection.
Set conn = New ADODB.Connection
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_file & ";" & _
"Mode=Read;" & _
"Persist Security Info=False"
conn.Open
|
|
This example reads data and displays the values in a ListBox.
|
|
Dim rs As ADODB.Recordset
' Open the Recordset.
Set rs = conn.Execute("SELECT * FROM Books", , _
adCmdText)
' List the data.
Do While Not rs.EOF
' The following statement would cause an
' error because the connection is read-only.
' rs!Title = "XXX"
txt = ""
For Each fld In rs.Fields
txt = txt & Trim$(fld.Value) & vbTab
Next fld
If Len(txt) > 0 Then txt = Left$(txt, Len(txt) - 1)
List1.AddItem txt
rs.MoveNext
Loop
rs.Close
conn.Close
|
|
|
|
|
|