以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 怎么导入多个mdb中的多个表 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=147564) |
||||
-- 作者:ymli -- 发布时间:2020/3/19 14:50:00 -- 怎么导入多个mdb中的多个表 代码如下:
Dim dlg As New OpenFileDialog dlg.Filter = "Access文件|*.mdb" dlg.MultiSelect = True \'允许选择多个文件 If dlg.ShowDialog =DialogResult.OK Then For Each fl As String In dlg.FileNames Dim mg As New Merger mg.SourcePath = fl Dim name As String Dim year As Integer For year = 2019 To 2019 Step 1 Dim month As Integer For month = 1 To 12 Step 1 If month < 10 Then
name = year
& "0"
& month & "_Memory"
mg.SourceTableName
= name mg.DataTableName = name
mg.Merge() Else If month < 13
name = year
& month & "_Memory"
mg.SourceTableName
= name mg.DataTableName = name
mg.Merge()
Continue For End If Next year
= year + 1 Next Next End If [此贴子已经被作者于2020/3/19 14:53:42编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2020/3/19 15:02:00 -- Dim dlg As New OpenFileDialog dlg.Filter = "Access文件|*.mdb" dlg.MultiSelect = True \'允许选择多个文件 If dlg.ShowDialog =DialogResult.OK Then For Each fl As String In dlg.FileNames Dim name As String Dim year As Integer For year = 2019 To 2019 Dim month As Integer For month = 1 To 12 name = year & format(month,"00") & "_Memory" If DataTables.Contains(name) Then Dim mg As New Merger mg.SourcePath = fl mg.SourceTableName = name mg.DataTableName = name mg.Merge() Else Dim im As New Importer im.SourcePath = fl im.SourceTableName = name im.NewTableName = name im.Import End If Next Next Next End If
[此贴子已经被作者于2020/3/19 15:35:00编辑过]
|
||||
-- 作者:ymli -- 发布时间:2020/3/19 15:24:00 -- 编译错误,DataTablename不是Importer的成员。 错误代码:im.DataTableName = name 此外能在整理后的表中增加一列linename =1的语句吗
[此贴子已经被作者于2020/3/19 15:35:53编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2020/3/19 15:35:00 -- Dim im As New Importer im.SourcePath = fl im.SourceTableName = name im.NewTableName = name im.Import
|
||||
-- 作者:ymli -- 发布时间:2020/3/19 15:42:00 -- 运行错误:SELECT 子句中包含一个保留字、拼写错误或丢失的参数,或标点符号不正确。 能在增加一列linename 吗,所有的值都是1
|
||||
-- 作者:有点蓝 -- 发布时间:2020/3/19 15:50:00 -- 1、要导入的数据和已有的表结构不一致 |
||||
-- 作者:ymli -- 发布时间:2020/3/19 15:58:00 --
|
||||
-- 作者:有点蓝 -- 发布时间:2020/3/19 16:09:00 -- 要导入的mdb数据库是不是没有这些表?msgbox(name = year & format(month,"00") & "_Memory") 或者是要导入的mdb表的结构和foxtable里的表结构不一致
|
||||
-- 作者:ymli -- 发布时间:2020/3/19 16:46:00 --
而且mdb表的结构没有什么特别的,还是不知道问题出在哪里,mdb数据参照附件 |
||||
-- 作者:有点蓝 -- 发布时间:2020/3/19 17:15:00 -- 代码是遍历12个月的,但是数据库里很多都只有5~12月份的表格,导入不存在的表格当然有问题了。 Dim dlg As New OpenFileDialog dlg.Filter = "Access文件|*.mdb" dlg.MultiSelect = True \'允许选择多个文件 Dim lst As List(Of String) If dlg.ShowDialog =DialogResult.OK Then For Each fl As String In dlg.FileNames If Connections.Contains("test") Then Connections.Delete("test") Connections.Add("test","Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & fl & ";Persist Security Info=False") \'动态连接数据库 lst = Connections("test").GetTableNames \'获取数据源里所有的表名 Dim name As String Dim year As Integer For year = 2019 To 2019 Dim month As Integer For month = 1 To 12 name = year & format(month,"00") & "_Memory" If lst.Contains(name ) Then \'如果数据库包含这个表 If DataTables.Contains(name) Then Dim mg As New Merger mg.SourcePath = fl mg.SourceTableName = name mg.DataTableName = name mg.Merge() Else Dim im As New Importer im.SourcePath = fl im.SourceTableName = name im.NewTableName = name im.Import End If End If Next Next Next End If |