VB.Net程序设计:ADO.Net读取Access表架构-创新互联
程序只是记录而已,还没有完成。
成都创新互联专业网站建设、做网站,集网站策划、网站设计、网站制作于一体,网站seo、网站优化、网站营销、软文发稿等专业人才根据搜索规律编程设计,让网站在运行后,在搜索中有好的表现,专业设计制作为您带来效益的网站!让网站建设为您创造效益。请不要模仿。
- 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
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
分享标题:VB.Net程序设计:ADO.Net读取Access表架构-创新互联
网页路径:http://pwwzsj.com/article/djdsps.html