注册 登录
编程论坛 ASP技术论坛

主键ID自动编号功能实现

andy292 发布于 2016-11-12 19:33, 5714 次点击
您好!我是初学者,请问我的ACCESS数据库因为需要按新闻时间排序,故而取消了主键ID的自动增加功能,现在导致添加新闻也无法添加了
sql="select * from news where (id is null)"
原来添加新闻的ID是这样的,现在因为无法自增,所以无法生成新的ID,我添加新闻需要自己设置ID号,我加了一个INPUT,设置为ID号,请问怎么才能在ASP中实现自己找到上一篇新闻的ID号,再保存新的新闻时自动加1呢。


[size=12px][此贴子已经被作者于2016-11-12 19:35编辑过]

9 回复
#2
andy2922016-11-12 19:35
请求帮助
#3
andy2922016-11-13 15:56
怎么办呢?现在发新闻我需要自己在INPUT中设定ID号码,有没有找到上一篇新闻的ID好的指针代码呢
#4
xss_wl2016-11-13 18:46
连个问题都描述不清,叫别人怎么帮你
#5
hujj2016-11-13 19:57
ID的编号有规则么,如果无特定的规则就好办了,先获得ID的最大值,然后加1作为新记录的ID编号。
#6
andy2922016-11-15 13:00
先获得ID的最大值,然后加1作为新记录的ID编号,嗯,这可以,但是怎么取ID的最大值呢?SQL代码有吗
#7
andy2922016-11-15 13:06
set rs=server.createobject("adodb.recordset")
sql="select * from news where (id is null)"
rs.open sql,conn,1,3
rs.addnew
rs("title")=title
rs("oStyle")=request.form("oStyle")
rs("oColor")=request.form("oColor")
rs("content")=demo
rs("come")=come
rs("user")=user
rs("bigclassname")=bigclassname
rs("smallclassname")=smallclassname、
rs("ID")=ID
rs("picurl")=request.form("uppic")
rs("top")=request.form("top")
if ok<>"" then rs("ok") = ok
if firstimagename<>"" then rs("firstimagename") = firstimagename
rs("tuijian")=request("tuijian")
if session("userkey")>8 then
rs("ifshow")=1
end if
rs.update
rs.close
#8
andy2922016-11-15 13:09
<%
if request.form("subsave")="subok" then
title=request.form("title")
bigclassname=request.form("bigclassname")
smallclassname=request.form("smallclassname")
ID=request.form("ID")
firstimagename=request.form("pic_url")
for i = 1 to request.form("demo").count
    scontent = scontent & request.form("demo")(i)
next
demo=scontent
if len(demo)=0 then
    response.write"<center><font color=#ff0000 size=2>内容不能为空呀!</font></center>"
    response.write"<center><font size=2><a href=# onclick=history.go(-1)>按这里返回</a></font></center>"
    response.end
end if
#9
andy2922016-11-15 13:39
如何表示连续的记录号有以下几个办法:
1、再建立一个专门用来存放记录号的字段,比如 RecordNo
    添加记录时可以用 MAX(recordNO)+1 的方法。
    当要删除某条记录时,比如这条记录的recordNo=6,我们用

   

delete from table where recordNo=6

    来做。这样就会产生空号,然后再用

   

update table set recordno=recordno-1 where recordno>6

    即可

2、在表中不存放记录号的数据,用sql查询自动生成

select [id],a,b,c,(select count(*) from table table2 where table2.[id]<=table1.[id]) as recordno from table table1 order by [id]
#10
eournet2016-11-24 13:51
dd=request("id")
id=dd-1
1