程序只是记录而已,还没有完成。
创新互联建站专业为企业提供兴安网站建设、兴安做网站、兴安网站设计、兴安网站制作等企业网站建设、网页设计与制作、兴安企业网站模板建站服务,十年兴安做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
请不要模仿。
- 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