更新产品批号的实际发货日期,设计一个导入按钮,导入的excel表只有2列:产品批号,实际发货日期。
但是导入后,已有的产品批号还是新增数据,并没有更新数据。 错误提示 产品批号是唯一值。
此主题相关图片如下:错误提示.png
代码如下:
以下内容为程序代码:
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