这样才不会重复
Select e.DataCol.Name
Case "订货日期","厂家编号"
If e.DataRow.isnull("采购单号") Then
If e.DataRow.IsNull("订货日期") OrElse e.DataRow.IsNull("厂家编号") Then
e.DataRow("采购单号") = Nothing
Else
Dim d As Date = e.DataRow("订货日期")
Dim bh As String = "SM-" & e.DataRow("厂家编号") & "" & Format(d,"yy") & "" '生成编号的前缀
e.DataRow.Save
Dim max As String
Dim idx As Integer
Dim flt As String
flt = "采购单号 like '" & bh & "%' And [_Identify] <> " & e.DataRow("_Identify")
max = e.DataTable.SQLCompute("Max(采购单号)",flt) '取得该年的相同厂家编号的最大采购单号
If max > "" Then '如果存在最大采购单号
idx = CInt(max.Substring(bh.Length,2)) + 1 '获得最大采购单号的后两位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("采购单号") = bh & Format(idx,"00")
e.DataRow.Save
End If
End If
End Select
[此贴子已经被作者于2015/7/10 14:53:13编辑过]