0
votes

Whenever I want to select tables names from specific Ms Access 2007 database, I use this SQL request:

SELECT name from msysobjects WHERE type=1 and flags=0

My VB.NET source code:

 Connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
                     "Data Source=" & Text1.Text
        Connection.Open()
        ' sql = "SELECT MSysObjects.Name AS table_name FROM MSysObjects"
        sql = "SELECT name from msysobjects WHERE Type = 1 And flags = 0"
        Dim commande As OleDbCommand
        commande = New OleDbCommand(sql, Connection)
        Dim dataReader As OleDbDataReader

        Try
            dataReader = commande.ExecuteReader()
            While (dataReader.Read())
                tableNameBox.Text = dataReader.GetString(0)
            End While

        Catch ex As Exception
            MsgBox("Problème de connection " & ex.Message())

        End Try

I always get this exception:

no read permission on 'msysobjects'

My purpose is to show tables names in comboBox Thank you

1
If you have a new question, please ask it as a new question. Do not change this one after you've received a useful valid answer. Thank you for your cooperation. - HansUp

1 Answers

3
votes

You don't need to access the system tables directly. You can use the GetSchema method to retrieve that information. For example, to retrieve a list of the "regular" (non-system) tables you can use this:

Using conn As New OleDbConnection(myConnectionString)
    conn.Open()
    Dim dt As DataTable = conn.GetSchema("TABLES", {Nothing, Nothing, Nothing, "TABLE"})
    For Each dr As DataRow In dt.Rows
        Console.WriteLine(dr("TABLE_NAME"))
    Next
End Using

For more information, see

OleDbConnection.GetSchema Method (String, String())