代码二:
Public Sub form673_save_Ajax(rq As Request)
Me.tablesave(rq) '保存数据表
Dim dr As DataRow = rq.result '返回当前保存的数据行,可再处理数据
If dr IsNot Nothing Then
Dim lb As String = dr("分类代码")
Dim idx As Integer
Dim cmd As N ew S QLCommand
cmd.Conne ctio nName = "主数据源"
cmd.CommandText = "Sele ct * From 办案装备_管理台账 where 分类代码 = '" & lb & "' "
Dim dt As DataTable = cmd.ExecuteReader()
If dt.DataRows.Count>1 Then
cmd.CommandText = "sel ect Max(编号) from 办案装备_管理台账 where 分类代码 = '" & lb & "'"
Dim max As String
max = cmd.ExecuteScalar()
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(max.length - 3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
Else
idx = 1 '否则顺序号等于1
End If
If dr("编号")<> Nothing Then
Else
dr("编号")=lb & Format(idx,"000")
End If
dr.Save
End If
rq.e.WriteString(rq.msg.ToString)
End Sub
运行效果:【数据库中会有两个001,然后会002,003,004递增,有没有办法修正上述代码,只让001出现一次】
此主题相关图片如下:11.png