Tables("表A").AllowEdit=True
Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "EXCEL文件|*.XLS" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim c As Integer = 0
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("表A").StopRedraw()
'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim nms() As String = {"客户编码","货号","尺寸_宽度","货描","材料","数量单位","价格"}
'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
For n As Integer = 1 To Sheet.Rows.Count - 1
Dim bh As String = sheet(n,1).Text
Dim dr As DataRow = DataTables("表A").SQLFind("货号 = '" & bh & "'")
If dr IsNot Nothing Then '如果存在同编号的货号
c=c + 1
Dim m As Integer = nms.Length - 2
Dim y As Integer = nms.Length - 1
dr("价格") = Sheet(n,y).Value
dr("数量单位") = Sheet(n,m).value
dr.Save
End If
Next
Tables("表A").ResumeRedraw()
MessageBox.Show("导入完成,共导入" & c & "条记录")
Tables("表A").save
End If