这里出错,肯定是获取的值长度不够:
Dim bh As String
Dim max As String
Dim pf As String = "yyMMdd"
e.DataRow("Riqi") = Date.Today()
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
cmd.commandText = "Select max(Danhao) From Bill"
max = cmd.ExecuteScalar
If max = "" OrElse Max.Length <> 9 Then
bh = Format(e.DataRow("Riqi"), pf & "001")
Else
max = max.Substring(6,3)
bh = Format(e.DataRow("Riqi"), pf) & Format(max+1, "000")
End If
e.DataRow("Danhao") = bh