在表的DataRowAdding 写了下面代码,
Dim d As Date=Date.Today '以当天的年月作为编号的前6位
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim bh As String = Format(d,"yyyy-MM")
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("max(产品编号)","Substring(产品编号,1,4)= & y & and Substring(产品编号,5,2)= & m & ") ‘查找年,月相同的编号的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(8,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("产品编号") = bh & "-" & Format(idx,"000")
编号不会增加
[此贴子已经被作者于2018/2/5 14:33:34编辑过]