Dim lb As String = "DY"
Dim max As String
Dim idx As Integer
Dim cmd As New SQ LCommand
cmd.Conn ectio nNa me = "主数据源"
cmd.Comm andText = "Se lect * From 台账"
Dim dt As DataTable = cmd.ExecuteReader()
Dim dr As DataRow = dt.DataRows(dt.DataRows.Count - 1) '获得最后一行
output.show(dr("_Identify"))
max = dt.Compute("Max(编号)","分类代码 = '" & lb & "'And [_Identify] <> " & dr("_Identify")) '取得该类别的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(2,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
output.show(lb & Format(idx,"000"))
---------------------------
版本:2022.1.30.2
---------------------------
代码执行出错,错误信息:
System.InvalidCastException: 从字符串“ZBD”到类型“Integer”的转换无效。 ---> System.FormatException: 输入字符串的格式不正确。
在 Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)
在 Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
--- 内部异常堆栈跟踪的结尾 ---
在 Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
在 UserCode.Test()
---------------------------
确定
---------------------------
[此贴子已经被作者于2022/12/14 17:34:45编辑过]