自己照帮助改了个内部函数,但听有点蓝版主说会有重复编号Dim getbh As String 'return 编号,pf 是前缀
Dim nm As String=Args(0) '读参数1,表名
Dim pf As String=Args(1)
Dim bhformat As String = Args(2)
Dim cmd1 As New SQLCommand
Dim cmd2 As New SQLCommand
Dim Key As Integer
cmd1.ConnectionName = DataSource '设置数据源名称
cmd2.ConnectionName = DataSource
cmd1.commandText = "Select Count(*) F rom [getnumberid] Where [前缀] = '" & pf & "' And 表名 = '" & nm & "'"
If cmd1.ExecuteScalar = 0 Then '如果编号表不存在前缀的行,那么增加一行
cmd1.commandtext = "Inser t Into getnumberid (表名, 前缀, 顺序号) Values('" & nm & "','" & pf & "',1)"
cmd1.ExecuteNonQuery
End If
cmd1.commandText = "Select [顺序号] F rom [getnumberid] Where [前缀] = '" & pf & "' And 表名 = '" & nm & "'"
Do
Key = cmd1.ExecuteScalar() '从后台获得顺序号
cmd2.commandText = "U pdate [getnumberid] Set [顺序号] = " & (Key + 1) & " Where [顺序号] = " & Key & " And [前缀] = '" & pf & "' And 表名 = '" & nm & "'"
If cmd2.ExecuteNonQuery() > 0 Then '更新顺序号
Exit Do '更新成功则退出循环
End If
Loop
getbh = pf & "-" & Format(Key,bhformat)
Return getbh