If e.DataCol.Name = "RQ" Then
If e.DataRow.IsNull("RQ") Then
e.DataRow("BH") = Nothing
Else
Dim bh As String = Format(e.DataRow("RQ"),"yyyyMMdd") '取得编号的8位前缀
If e.DataRow("BH").StartsWith(bh) = False '如果编号的前8位不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(BH)","RQ = #" & e.DataRow("RQ") & "#") '取得该天的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(9,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("BH") = bh & "-" & Format(idx,"000")
End If
End If
End If
上述代码只有在加载的数据之后才会生成连续性编号;如果没有加载数据,在同一天重复打开文件,编号将会从******001开始重复编号。
如何在未加载数据的情况下取得内部数据表最大的编号?