程序只是记录而已,还没有完成。
请不要模仿。
原文链接:https://www.f2er.com/vb/260861.html
- ImportsSystem.Data
- ImportsSystem.Data.OleDb
- PublicClassForm1
- DimConnStrAsString=String.Format("Provider=Microsoft.Jet.OLEDB.4.0;DataSource={0};UserId=admin;Password={1};","D:\product.MDB","")
- DimconnAsOleDb.OleDbConnection
- DimcmdAsOleDb.OleDbCommand
- DimsqlAsString
- PrivateSubForm1_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Load
- 'cmd=NewOleDbCommand(sql,conn)
- 'cmd.ExecuteNonQuery()
- conn=NewOleDb.OleDbConnection(ConnStr)
- EndSub
- PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
- DimdtAsDataTable
- DimtblAsDataTable
- Dimtbl2AsDataTable
- conn.Open()
- 'tbl=conn.GetSchema()=数据库的所有架构信息。
- '获取用户表
- tbl=conn.GetSchema("tables",NewString(){Nothing,Nothing,"table"})
- 'tbl=conn.GetSchema("tables")=所有表,包括系统表。
- tbl2=conn.GetSchema()
- '=不大支持的方法
- dt=conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,NewObject(){Nothing,"TABLE"})
- Me.ListBox1.Items.Clear()
- ForiAsInteger=0Todt.Rows.Count-1
- Me.ListBox1.Items.Add(dt.Rows(i)("TABLE_NAME").ToString())
- Next
- Me.DataGridView1.DataSource=tbl
- Me.DataGridView2.DataSource=tbl2
- conn.Close()
- EndSub
- PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click
- DimtblAsDataTable
- IfString.IsNullOrEmpty(Me.TextBox1.Text)=FalseThen
- conn.Open()
- tbl=conn.GetSchema("columns",Me.TextBox1.Text})
- Dimrows()AsDataRow=tbl.Select("","Ordinal_Position")
- Me.ListBox2.Items.Clear()
- ForEachrowAsDataRowInrows
- Me.ListBox2.Items.Add(row.Item("column_name"))
- Next
- Me.DataGridView2.DataSource=tbl
- conn.Close()
- EndIf
- EndSub
- PrivateSubListBox1_SelectedIndexChanged(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesListBox1.SelectedIndexChanged
- IfMe.ListBox1.SelectedItems.Count>0Then
- Me.TextBox1.Text=Me.ListBox1.SelectedItem.ToString
- EndIf
- EndSub
- PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesBtnGetDatatable.Click
- DimdbAsNewAccessHelper
- db.connStr=ConnStr
- IfMe.TextBox1.Text>""Then
- db.Open()
- Me.DataGridView3.DataSource=db.GetDataView("select*from"&Me.TextBox1.Text)
- EndIf
- EndSub
- EndClass