吃晚饭,迟了
程序代码:
Public Class frm_data Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdopen.Click Dim ds As New Data.DataSet() Dim dbaname As String = txtdba.Text '指定数据库文件路径及名称 Dim connStr As String = "provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & CurDir() & dbaname Dim tabname As String = cmbtable.Text Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(connStr) Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand Dim sql As String = "select * from " & tabname conn.Open() cmd.Connection = conn Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sql, conn) ds.Clear() da.Fill(ds, "pylj") DataGridView1.DataSource = Nothing Dim k As Integer = DataGridView1.ColumnCount - 1 DataGridView1.DataSource = ds.Tables(0) DataGridView1.Refresh() Dim n As Integer = ds.Tables(0).Columns.Count - 1 Dim y As Integer = cmbfiled.Items.Count - 1 For x As Integer = 0 To y cmbfiled.Items.Clear() Next cmbfiled.Refresh() For i As Integer = 0 To n cmbfiled.Items.Add(ds.Tables(0).Columns(i).ColumnName) Next cmbfiled.SelectedIndex = 0 conn.Close() End Sub Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick On Error Resume Next MsgBox(DataGridView1.CurrentCell.Value.ToString) End Sub Private Sub frm_data_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load txtdba.Text = "\data\py.mdb" End Sub Private Sub butconn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butconn.Click cmbtable.Items.Clear() For i As Int16 = 0 To GetAllTableName.Count - 1 cmbtable.Items.Add(GetAllTableName.Item(i).ToString) Next cmbtable.SelectedIndex = 0 End Sub Function GetAllTableName() As System.Collections.ArrayList Dim t As New System.Collections.ArrayList() Dim Rs As New ADODB.Recordset() Dim dbaname As String = txtdba.Text '指定数据库文件路径及名称 Dim connStr As String = "provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & CurDir() & dbaname Dim conn As New ADODB.Connection conn.Open(connStr) Rs = conn.OpenSchema(ADODB.SchemaEnum.adSchemaTables) Do While Not rs.EOF If rs("TABLE_TYPE").Value = "TABLE" Then t.Add(rs("TABLE_NAME").Value) End If rs.MoveNext() If rs.EOF Then Exit Do Loop Rs.Close() Rs = Nothing Return t End Function Private Sub cmbtable_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbtable.SelectedIndexChanged Button1_Click(sender, e) End Sub End Class
===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================