以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [原创]导入问题,已有数据还是新增。 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=136661) |
-- 作者:by0521 -- 发布时间:2019/6/18 16:29:00 -- [原创]导入问题,已有数据还是新增。 更新产品批号的实际发货日期,设计一个导入按钮,导入的excel表只有2列:产品批号,实际发货日期。 代码如下: 以下内容为程序代码: 1 Dim dlg As New OpenFileDialog 2 dlg.Filter = "Excel文件|*.xls;*.xlsx" 3 If dlg.ShowDialog =DialogResult.OK Then 4 Dim t As Table = Tables("入库") 5 t.StopRedraw() 6 Dim Book As New XLS.Book(dlg.FileName) 7 Dim Sheet As XLS.Sheet = Book.Sheets(0) 8 Dim newcount As Integer = 0 9 Dim oldcount As Integer = 0 10 For n As Integer = 1 To Sheet.Rows.Count -1 11 Dim r As DataRow = t.DataTable.Find("产品批号 = \'" & sheet(n, 0).text & "\'") 12 If r Is Nothing Then 13 r = t.DataTable.AddNew() 14 newcount += 1 15 Else 16 oldcount += 1 17 End If 18 For i As Integer = 0 To sheet.Cols.Count -1 19 Dim cname As String = sheet(0, i).text 20 If t.Cols.Contains(cname) Then 21 r(cname) = sheet(n, i).Text 22 End If 23 Next 24 Next 25 msgbox("新增" & newcount & " " & "更新旧数据" & oldcount) 26 t.ResumeRedraw() 27 End If |
-- 作者:有点甜 -- 发布时间:2019/6/18 16:55:00 -- 判断一下值是不是为空,如
If sheet(n, 0).text = Nothing Then msgbox("空值不比较") Else \'这里写本来的代码 End If |