CodeItBetter Programming Another VB Programming Blog

How to Use ADO to get data from a read-only Access database

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'Database - How to Use ADO to get data from a read-only Access 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
Filed under: Database Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.