Dim bh As String
Dim dr As DataRow = e.DataRow
Dim pf As String
Dim max As String
Dim cmd As New SQLCommand
Dim dt As DataTable
pf = Format(dr("Riqi"),"yyMMdd") '获得编号的前缀
cmd.C
cmd.commandText = "Select top 1 Danhao,* From Bill_Shou Where Danhao Like '" & pf & "*'"
dt = cmd.ExecuteReader
dr = dt.DataRows(0)
If dr("Danhao") Is Nothing Then
bh = Format(dr("Danhao"),"yyMMdd001")
Else
max = dr("Danhao")
max = cint(max.Substring(7,3)) + 1
bh = pf & format(max,"000")
End If
e.DataRow("Danhao") = bh
以上代码目的是如果是今天的第一单,单号就是121019001,第二单是121019002,依次类推。
运行报错,错误代码为
Exception has been thrown by the target of an invocation.