Dim TableDB As DataTable = DataTables("TableDB")
Dim FieldDB As DataTable = DataTables("FieldDB")
Dim dlg As New OpenFileDialog
dlg.Filter = "Accese文件|*.mdb"
dlg.MultiSelect = True
dlg.Title = "请用鼠标单选或多选*.mdb格式的文件,然后点击确定"
If dlg.ShowDialog = DialogResult.Ok Then
For Each File As String In dlg.FileNames
'遍历所选的Access文件名
If Connections.Contains("newsql") Then '判断是否存在某一数据源
Connections.Delete("newsql") '如果有就删除
End If
Connections.Add("newsql","Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & file & ";Persist Security Info=False") '把选择的Access文件新建一个数据源
Dim conn As Connection = Connections("newsql") '定义数据源
Dim lst As List(Of String)
lst = conn.GetTableNames '所有表
For Each nm As String In lst
Dim cmd As new QueryBuilder
cmd.ConnectionName = "newsql"
cmd.SelectString = "select * from {" & nm & "} where 1=2"
cmd.TableName = nm
cmd.Build
Dim tb As DataTable = DataTables(nm)
Dim mColCount As Integer = tb.dataCols.count()
Dim dr As DataRow = TableDB.addnew()
dr("Fullmdbname") = file
dr("mdbname") = FileSys.GetName(file)
dr("cnname") = conn.name
dr("tablename") = nm
dr("ColCount") = mColCount
'--------------------------------------------
'For Each dc As DataCol In tb.DataCols
'Dim dr1 As DataRow = FieldDB.addnew()
'dr1("表名") = nm
'dr1("列名") = dc.name
'
'dr1("列类型") = dc.datatype.Name
'dr1("字符长度") = dc.MaxLength
'
'dr1("表达式内容") = dc.Expression
'dr1("表标题") =tb.Caption
'dr1("列标题")=dc.caption
'dr1("表类别") = tb.Type
''-------------------------------------------------------------
'Dim dt As DataTable = DataTables("临时表")
For Each dc As DataCol In tb.DataCols
Dim dr1 As DataRow = FieldDB.AddNew()
dr1("Tablename") = nm
dr1("列名") = dc.name
dr1("表达式内容") = dc.Expression
dr1("表标题") =tb.Caption
dr1("列标题")=dc.caption
dr1("表类别") = tb.Type
dr1("mdbName") = dr("mdbname")
If dc.DataType.Name = "String" Then
dr1("字符长度") = dc.MaxLength
MessageBox.show(dc.MaxLength)
End If
Select Case dc.DataType.Name
Case "String"
If dc.MaxLength > 255 Then
dr1("列类型") = "备注"
Else
dr1("列类型") = "字符"
End If
Case "DateTime"
dr1("列类型") = "日期时间"
Case "Boolean"
dr1("列类型") = "逻辑"
Case "Int32"
dr1("列类型") = "整数"
Case "Int16"
dr1("列类型") = "短整数"
Case "Byte"
dr1("列类型") = "微整数"
Case "Double"
dr1("列类型") = "双精度"
Case "Single"
dr1("列类型") = "单精度"
Case "Decimal"
dr1("列类型") = "高精度"
End Select
' DataTables("FieldDB").Save()
' DataTables("FieldDB").load()
Next
DataTables.unload(nm)
Next
Next
End If
Dim tv As WinForm.TreeView
tv =e.Form.Controls("TreeView1")
tv.BuildTree("TableDB","mdbname|tablename")