Foxtable(狐表)用户栏目专家坐堂 → 如何遍历Access文中的所有表?


  共有1698人关注过本帖树形打印复制链接

主题:如何遍历Access文中的所有表?

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/9/1 17:16:00 [显示全部帖子]

参考

 

Dim dlg As  new OpenFileDialog
If dlg.ShowDialog = DialogResult.OK Then
    If Connections.Contains("test") Then Connections.Delete("test")
    Connections.Add("test","Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dlg.FileName & ";Persist Security Info=False")
    For Each tn As String In Connections("test").GetTableNames
        Dim cmd As New SQLCommand
        Dim dt As DataTable
        cmd.ConnectionName = "test"
        cmd.CommandText = "SELECT * From {" & tn & "}"
        dt = cmd.ExecuteReader()
        For Each dr As DataRow In dt.DataRows
            Dim fdr As DataRow = DataTables(tn).Find("主键列名 = '" & dr("主键列名") & "'")
            If fdr Is Nothing Then fdr = DataTables("员工").AddNew()
            For Each dc As DataCol In dt.DataCols
                fdr(dc.name) = dr(dc.name)
            Next
        Next
    Next
End If


 回到顶部