[英]How to retrieve Ms access tables names from specific database using SQL in VB.NET
Whenever I want to select tables names from specific Ms Access 2007 database, I use this SQL request: 每当我想从特定的Ms Access 2007数据库中选择表名称时,我都会使用以下SQL请求:
SELECT name from msysobjects WHERE type=1 and flags=0
My VB.NET source code: 我的VB.NET源代码:
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'
对“ msysobjects”没有读取权限
My purpose is to show tables names in comboBox Thank you 我的目的是在comboBox中显示表名称谢谢
You don't need to access the system tables directly. 您不需要直接访问系统表。 You can use the
GetSchema
method to retrieve that information. 您可以使用
GetSchema
方法检索该信息。 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()) OleDbConnection.GetSchema方法(String,String())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.