0

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
  • 2
    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. Commented May 26, 2016 at 2:39

1 Answer 1

3

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())

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Gord Thompson, thank you for the your answer. I Really want to informe you that I have edited my post. Thank you. Best regards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.