这样试试:
Select e.DataCol.Name
Case "登记日期","类别"
If e.DataRow.IsNull("登记日期") OrElse e.DataRow.IsNull("类别") Then
e.DataRow("编号") = Nothing
Else
Dim d As Date = e.DataRow("登记日期")
Dim y As Integer = d.Year
Dim bh As String = e.DataRow("类别") & "[" & Format(d,"yyyy") & "]" '生成编号的前缀
If e.DataRow("编号").StartsWith(bh) = False '如果立案编号前缀不符
Dim idx As Integer
Dim max,flt,s1 As String
Dim d1,d2 As Date
d1 = New Date(y,1,1)
d2 = New Date(y,12,31)
Dim v1 as string() ={e.DataRow("类别"),e.DataRow("_Identify"),d1,d2}
s1 ="类别 ='{0}' and [_Identify] ={1} and 登记日期 >= #{2}# and 登记日期 <= #{3}#"
flt = String.format(s1,V1(0),V1(1),v1(2),v1(3))
max = e.DataTable.Compute("Max(编号)",flt) '取得区划机关行为简称的最大单据编号
If max > "" Then '如果存在最大立案编号
idx = CInt(max.Substring(8,3)) + 1 '获得最大单据编号的后四位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("编号") = bh & Format(idx,"000")
End If
End If
End Select