劳烦老师给我看看,我用身份证号前6位来生成自动编号,以下代码问题出到哪?
Select Case e.DataCol.name
Case "身份证号码"
If e.DataRow.IsNull("身份证号码") Then
e.DataRow("ID") = Nothing
Else
Dim bm As String = e.DataRow("身份证号码").SubString(0,6)
If e.DataRow("ID").StartsWith(bm) = False '如果编号的前6位不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(ID)","身份证号 >= #" & bm & "# And bm <= #" & bm & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该地区的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(7,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("ID") = bm & "-" & Format(idx,"000")
End If
End If
End Select