老师:我这段代码可以根据订单号判定新增,但不能把excel的数据更新到窗口表里。麻烦看看是那没有对呢? Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog =DialogResult.OK Then
Dim t As Table = Tables("cwbc_Table1")
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.SQLFind("订单号 = '" & 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