Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共4 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:关联表导入

1楼
longyanlin 发表于:2024/10/1 18:00:00
各位老师国庆快乐:
以下代码是给DataTables导入数据,现在我想要给关联表Tables(订单.订单明细)导入数据,请问如果修改代码,谢谢!
Dim dt As DataTable = DataTables("订单明细")
Dim Result As DialogResult
Result = MessageBox.Show("确定要导入吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
    Dim dlg As New OpenFileDialog
    dlg.Filter = "Excel文件|*.xlsx"
    dlg.MultiSelect = True '允许选择多个文件
    If dlg.ShowDialog =DialogResult.OK Then
        Dim Book As New XLS.Book(dlg.FileName)
        Dim Sheet As XLS.Sheet = Book.Sheets("订单明细")
        dt.ResumeRedraw()
        dt.StopRedraw()
        'systemready = False
        Dim nms As New Dictionary(Of String, Integer)
        Dim dic As new Dictionary(Of DataRow, Integer)
        Dim ls As new List(Of Integer)
        For c As Integer = 0 To sheet.Cols.Count - 1
            If  dt.DataCols.Contains(sheet(0,c).Text.replace(" ", "")) Then
                nms.Add(sheet(0,c).Text.replace(" ", ""), c)
            End If
        Next
        For l As Integer = 1 To Sheet.Rows.Count -1
            If sheet(l, nms("物料代号")).Text.trim > "" Then
                Dim ndr As DataRow = dt.AddNew
                For Each m As String In nms.keys
                    If dt.DataCols(m).IsBoolean Then
                        If Sheet(l,nms(m)).Text = "" OrElse Sheet(l,nms(m)).Text = "False" OrElse Sheet(l,nms(m)).Value = 0 Then
                            ndr (m) = False
                        Else
                            ndr (m) = True
                        End If
                    Else If dt.DataCols(m).Expression > "" Then
                        '表达式列
                    Else If dt.DataCols(m).IsNumeric Then
                        ndr (m) = val(Sheet(l,nms(m)).Value)
                    Else If dt.DataCols(m).IsDate Then
                        Dim d As Date
                        If Date.TryParse(Sheet(l,nms(m)).Value, d)
                            ndr (m) = d
                        End If
                    Else
                        
                        ndr (m) = Sheet(l,nms(m)).Value
                    End If
                Next
            End If
        Next
        dt.ResumeRedraw()
        'systemready = True
    End If
End If
2楼
有点蓝 发表于:2024/10/5 20:36:00
Dim dt As Table = Tables("订单明细")
Dim Result As DialogResult
……
     For c As Integer = 0 To sheet.Cols.Count - 1
            If  dt.Cols.Contains(sheet(0,c).Text.replace(" ", "")) Then
                nms.Add(sheet(0,c).Text.replace(" ", ""), c)
            End If
        Next
        For l As Integer = 1 To Sheet.Rows.Count -1
            If sheet(l, nms("物料代号")).Text.trim > "" Then
                Dim ndr As Row = dt.AddNew
                For Each m As String In nms.keys
                    If dt.Cols(m).IsBoolean Then
                        If Sheet(l,nms(m)).Text = "" OrElse Sheet(l,nms(m)).Text = "False" OrElse Sheet(l,nms(m)).Value = 0 Then
                            ndr (m) = False
                        Else
                            ndr (m) = True
                        End If
                    Else If dt.Cols(m).datacol.Expression > "" Then
……
3楼
longyanlin 发表于:2024/10/7 12:49:00
请问这是什么错误,怎么导入不了
图片点击可在新窗口打开查看此主题相关图片如下:错误提示.png
图片点击可在新窗口打开查看
4楼
有点蓝 发表于:2024/10/7 20:19:00
应该是execl第一行有重复的列名
共4 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .04688 s, 2 queries.