Dim Result As DialogResult
Result = MessageBox.Show("导入的Excel必须是在系统中导出的,否则会出错!存在相同记录时将进行略过", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
If Result = DialogResult.ok Then
Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "excel文件|*.xls|Excel2007文件|*.xlsx" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim c As Integer = 0
Tables("订单表").StopRedraw()
forms("独-正在更新").open
'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim nms() As String = {"下单日期","客户编码","客户名称","客户序号","物料编码","物料名称","规格","单位","需求量","分配量","实发量","实收量","物料备注","物料类别","订单状态","订单备注","订单编号","结算量","同步状态","分拣部","编辑者"}
'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
Dim k1 As String = ""
Dim k2 As String = ""
Dim st9 As String = ""
For n As Integer = 1 To Sheet.Rows.Count -1
If sheet(n,16).value <> k2 Then
Dim dr99 As DataRow
dr99=DataTables("订单表").fi nd("订单编号= '" & sheet(n,16).value & "'")
If dr99 Is Nothing Then
Dim wz As Integer = Tables("订单表").FindRow(dr99)
If wz >= 0 Then
MessageBox.show(wz)
Else
MessageBox.show("没找到")
End If
k1 = "no" '如果存在相同的单号,就设为否
k2 = sheet(n,16).value
st9 = st9 & vbcrlf & sheet(n,16).value & "【此订单系统中已存在,无法重复导入】"
Else
k1 = "ok"
k2 = sheet(n,16).value
End If
End If
实际上我们导入的excel表里面的单号是全新的,但是
dr99=DataTables("订单表").fi nd("订单编号= '" & sheet(n,16).value & "'")
在这一句的dr99都会存在,
这个是什么原因?
在BeforeLoadOuterTable中有设置:
If e.DataTableName = "订单表" Then
e.Se lectString = "Se lect * From {订单表} Where [结算量] Is Null"
End If
会跟这个有关系?