因为习惯了用字母表示年月,所以在DataRowAdding中写了个增加行则自动编号, 可是在取编号最大值得时候有点问题,请问如何修改?
If e.DataRow.IsNull("日期") Then
e.DataRow("日期") = Date.Now()
End If
Dim str As String = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim d As Date = e.DataRow("日期")
Dim y As Integer = d.Year - 2001
Dim m As Integer = d.Month - 1
Dim bh As String = str.Substring(y,1) & str.Substring(m,1)
If e.DataRow("编号").StartsWith(bh) = False
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("max(编号)","编号 like '" & bh & "*'")
If max > "" Then
idx = CInt(max.Substring(7,3)) + 1
Else
idx = 1
End If
e.DataRow("编号") = bh & "-" & Format(idx,"000")
End If