简体   繁体   English

vb.net列表框显示数据库中的表名称

[英]vb.net listbox display tables names from database

I need to list all the tables in the list box from the database.mdb file. 我需要从database.mdb文件列出列表框中的所有表。 Not the contents of the tables just the tables name using Microsoft.Jet.OLEDB.4.0 使用Microsoft.Jet.OLEDB.4.0不是表的内容只是表名

I'm new to vb.net, please help. 我是vb.net的新手,请帮助。

this is what i have so far.. and i keep getting errors 这是我到目前为止所拥有的..而且我不断出错


    Dim dbpath As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
    dbpath = New Uri(dbpath).LocalPath
    TextBox1.Text = dbpath + "\database.mdb"

    Dim userTables As DataTable = Nothing
    Dim connection As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection()
    connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; data source =" textbox1.text
    ' We only want user tables, not system tables
    Dim restrictions() As String = New String(4) {}
    restrictions(3) = "Table"
    connection.Open()
    ' Get list of user tables
    userTables = connection.GetSchema("Tables", restrictions)
    connection.Close()
    ' Add list of table names to listBox
    Dim i As Integer
    For i = 0 To userTables.Rows.Count - 1 Step i + 1
        ListBox1.Items.Add(userTables.Rows(i)(2).ToString())
    Next

You can use the following code segment to display the list of tables in a .mdb file Click Here to get reference 您可以使用以下代码段显示.mdb文件中的表的列表,请单击此处以获取参考。

Dim userTables As DataTable = Nothing
Dim connection As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection()
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;//your database path"
' We only want user tables, not system tables
Dim restrictions() As String = New String(4) {}
restrictions(3) = "Table"
connection.Open()
' Get list of user tables
userTables = connection.GetSchema("Tables", restrictions)
connection.Close()
' Add list of table names to listBox
Dim i As Integer
For i = 0 To userTables.Rows.Count - 1 Step i + 1
    ListBox1.Items.Add(userTables.Rows(i)(2).ToString())
Next

seem this the right answer 似乎这是正确的答案

Dim userTables As DataTable = Nothing
Dim connection As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection()
Dim source As String
source = TextDBPath.Text
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + source
Dim restrictions() As String = New String(3) {}
restrictions(3) = "Table"
connection.Open()
' Get list of user tables
userTables = connection.GetSchema("Tables", restrictions)
connection.Close()
' Add list of table names to listBox
Dim i As Integer
For i = 0 To userTables.Rows.Count - 1 Step i + 1
    cbox.items.add(userTables.Rows(i)(2).ToString())
Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM