Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse ADO to get data from a read-only Access database
KeywordsADO, Access, database, connect, read-only
CategoriesDatabase
 
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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated