您好,登錄后才能下訂單哦!
程序只是記錄而已,還沒有完成。
請不要模仿。
- Imports System.Data
- Imports System.Data.OleDb
- Public Class Form1
- Dim ConnStr As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; User Id=admin; Password={1};", "D:\product.MDB", "")
- Dim conn As OleDb.OleDbConnection
- Dim cmd As OleDb.OleDbCommand
- Dim sql As String
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- 'cmd = New OleDbCommand(sql, conn)
- 'cmd.ExecuteNonQuery()
- conn = New OleDb.OleDbConnection(ConnStr)
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim dt As DataTable
- Dim tbl As DataTable
- Dim tbl2 As DataTable
- conn.Open()
- 'tbl = conn.GetSchema() =數據庫的所有架構信息。
- '獲取用戶表
- tbl = conn.GetSchema("tables", New String() {Nothing, Nothing, Nothing, "table"})
- 'tbl = conn.GetSchema("tables") = 所有表,包括系統表。
- tbl2 = conn.GetSchema()
- '=不大支持的方法
- dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
- Me.ListBox1.Items.Clear()
- For i As Integer = 0 To dt.Rows.Count - 1
- Me.ListBox1.Items.Add(dt.Rows(i)("TABLE_NAME").ToString())
- Next
- Me.DataGridView1.DataSource = tbl
- Me.DataGridView2.DataSource = tbl2
- conn.Close()
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- Dim tbl As DataTable
- If String.IsNullOrEmpty(Me.TextBox1.Text) = False Then
- conn.Open()
- tbl = conn.GetSchema("columns", New String() {Nothing, Nothing, Me.TextBox1.Text})
- Dim rows() As DataRow = tbl.Select("", "Ordinal_Position")
- Me.ListBox2.Items.Clear()
- For Each row As DataRow In rows
- Me.ListBox2.Items.Add(row.Item("column_name"))
- Next
- Me.DataGridView2.DataSource = tbl
- conn.Close()
- End If
- End Sub
- Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
- If Me.ListBox1.SelectedItems.Count > 0 Then
- Me.TextBox1.Text = Me.ListBox1.SelectedItem.ToString
- End If
- End Sub
- Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGetDatatable.Click
- Dim db As New AccessHelper
- db.connStr = ConnStr
- If Me.TextBox1.Text > "" Then
- db.Open()
- Me.DataGridView3.DataSource = db.GetDataView("select * from " & Me.TextBox1.Text)
- End If
- End Sub
- End Class
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。