http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=50080
调试
……
Do
cmd.CommandText = "select ISNULL(sqdate,GETDATE() ) AS sqdate,preletter,len,ISNULL(number,0) AS number from getnumberid where Tablename='" & tbname & "' and Colname='" & clname & "'"
dt = cmd.ExecuteReader() '读行记录
'If dt Is Nothing Then ExecuteReader返回的表格不可能是nothing,至少返回了表结构,只是没有行
If dt.DataRows.count Then
Exit Do '没有行记录则直接退出返回
End If
dr = dt.DataRows(0) '取记录的第一行
numdate=dr("sqdate")
numpre=dr("preletter")
numlen=dr("len")
num=dr("number")
t = (sqldate - numdate).TotalDays
If t > 0 Then
'先读编号,根据编号更新。即使100个用户并发,也只有一个用户能成功申请,其余99个用户会申请失败,将会重新循环申请
cmd.commandtext = "Update getnumberid Set number =1,sqdate='" & sqldate & "' where Tablename='" & tbname & "' and Colname='" & clname & "' and number=" & num
msgbox(cmd.commandtext ) 把合并后的sql放到数据库里执行,看看有没有结果
xh=cmd.ExecuteNonQuery()
num = 1 '新的一天序列号置1
numdate = sqldate '填上新日期
Else
cmd.commandtext = "Update getnumberid Set number =" & num + 1 & " where Tablename='" & tbname & "' and Colname='" & clname & "' and number =" & num
msgbox(cmd.commandtext )
xh=cmd.ExecuteNonQuery()
num=num+1
End If
getbh=numpre.Trim() & "-" & CStr(numdate.year).SubString(2) & CStr(numdate.Month).PadLeft(2 ,"0") & CStr(numdate.Day).PadLeft(2 ,"0") & "-" & CStr(num).PadLeft(numlen ,"0")
Loop While xh=0 ‘xh=cmd.ExecuteNonQuery()没有更新到任何东西,说明没有符合条件的数据,xh一直都是0值,会一直循环’
Return getbh