09-04
11

ASP程序自增

set rs = server.createobject("adodb.recordset")
'这里ProdId 是数据库里,你要做自增的字段
sql = "select * from bproduc where ProdId is not null"
rs.cursorlocation = 3
rs.open sql,conn,1,1
if rs.bof and rs.eof then'数据库没有数据,则设为1,暂时存到autoid
autoid=1
else
totalid=rs.RecordCount'有数据,根据数据库记录总数增1存到autoid
autoid=totalid+1
end if
rs.close
set rs=nothing

autoidtxt=cstr(autoid)

for i=1 to totalid
'检查自动生成的编号是否有重复,若有重复则自动加1

set rs=conn.execute("select prodid from bproduc where prodid='"&autoidtxt&"'")
if not (rs.eof and rs.bof) then
autoid=autoid+1
autoidtxt=cstr(autoid)
end if
set rs=nothing
next


看一下我这代码,只做关键的简单注释,相信容易看懂。
学程序,要耐心,别懒。重要看动别人写程序的思路,把这种思路固化为自己今后写程序的经验。慢慢积累!

文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: 自增
相关日志:
评论: 0 | 引用: 0 | 查看次数: 275
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭