以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=110854)

--  作者:xh2207
--  发布时间:2017/12/11 10:05:00
--  [求助]

在论坛下载代码试运行运行,出现错误去。环境不符还是代码的问题,怎修改?请指教,感谢!

 

Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog =DialogResult.OK Then
    Dim t As Table = Tables("工程需求_订货明细表")
    t.StopRedraw()
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    Dim newcount As Integer = 0
    Dim oldcount As Integer = 0
    For n As Integer = 1 To Sheet.Rows.Count -1
        Dim r As DataRow = t.DataTable.Find("品名 = \'" & sheet(n, 0).text & "\'")
        If r Is Nothing Then
           r = t.DataTable.AddNew()
            newcount + = 1
        Else
            oldcount + = 1
        End If
        For i As Integer = 0 To sheet.Cols.Count -1
            Dim cname As String = sheet(0, i).text
            If t.Cols.Contains(cname) Then
                r(cname) = sheet(n, i).Text
            End If
        Next
    Next
    msgbox("新增" & newcount & "    " & "更新旧数据" & oldcount)
    t.ResumeRedraw()
End If

 

 

 


图片点击可在新窗口打开查看此主题相关图片如下:错误.png
图片点击可在新窗口打开查看

--  作者:有点甜
--  发布时间:2017/12/11 10:08:00
--  

If t.Cols.Contains(cname) Then

 

改成

 

If cname > "" AndAlso t.Cols.Contains(cname) Then


--  作者:xh2207
--  发布时间:2017/12/11 10:18:00
--  
感谢