*我有代码自动编号*
Sub AutoCount()
Dim daC As New SqlDataAdapter("select Max(couttime) From TbCourse where cusid='" & txtcustomerid.Text & "' ", conn)
Dim dsC As New DataSet
daC.Fill(dsC, "Course")
dsC.Tables(0).Clear()
daC.Fill(dsC, "Course")
txtcounttime.Text = Format(CInt(dsC.Tables(0).Rows(0).Item(0)) + 1, "0")
End Sub
我有Table Ex:
答案 0 :(得分:0)
You need to check, is there any entry for the given cusid
, if not it will return 1 (0 in case if you are +1 in the code), if the given cusid
exists, it will return the MAX value for the cusid
IF NOT EXISTS (SELECT cusid FROM TbCourse WHERE cusid = 'COL2')
SELECT 1 AS couttime
ELSE
SELECT MAX(couttime) AS couttime FROM TbCourse WHERE cusid = 'COL2'
Here COL2
is the txtcustomerid.Text
value.