关于记录上下移动问题 请帮忙
上移
new_id=cint(request( "new_id "))
Pid=new_id+1
set rscyc=server.CreateObject( "adodb.recordset ")
sql= "select * from bm_news where new_idsub= "&new_id& " "
rscyc.open sql,conn,1,3
rscyc( "new_idsub ")=rscyc( "new_idsub ")-1
rscyc.Update
set rscyco=server.CreateObject( "adodb.recordset ")
sqlcyco= "select * from bm_news where new_idsub= "&Pid& " "
rscyco.open sqlcyco,conn,1,3
rscyco( "new_idsub ")=rscyco( "new_idsub ")+1
rscyco.Update
rscyc.Close
rscyco.Close
set rscyc=Nothing
set rscyco=Nothing
我是这么写的 大家帮我看看 new_idsub 这个字段为标识字段
可是如果中间删除了 记录 +1或者 -1就取不到值了 大家 一般都怎么做 谢谢
------解决方案--------------------又见LZ,你想实现什么?
------解决方案--------------------在表中建一个字段如OrderID
'排序
if lcase(Action) = "order " then
On Error Resume Next
dim op , intMaxID
strID = request( "ID ")
op = request( "op ")
if Cstr(op) <> "1 " then op = -1
intMaxID = conn.execute( "select Max([OrderID]) from [Product] where CateID= "&CateID)(0)
intOrderID = conn.execute( "select [OrderID] from [Product] where ID= "&strID)(0)
'升 order - 1
if trim(op) = "1 " and intOrderID > 1 then
strSql = "Update [Product] Set [OrderID] = [OrderID] + 1 Where CateID= "&CateID& " and [OrderID] = " & intOrderID - 1
Conn.execute(strSql)
strSql = "Update [Product] Set [OrderID] = [OrderID] - 1 Where CateID= "&CateID& " and ID = " & strID
Conn.execute(strSql)
end if
'降 order + 1
if trim(op) = "-1 " and intOrderID < intMaxID then
strSql = "Update [Product] Set [OrderID] = [OrderID] - 1 Where CateID= "&CateID& " and [OrderID] = " & intOrderID + 1
Conn.execute(strSql)
strSql = "Update [Product] Set [OrderID] = [OrderID] + 1 Where CateID= "&CateID& "and ID = " & strID
Conn.execute(strSql)
end if
end if
------解决方案--------------------建议加一个排序字段