在asp中怎样实现数据的汇总并把数据赋给变量

来源:百度知道 编辑:UC知道 时间:2024/06/04 10:33:49
我建了一个access库,其中有lr子表,该表中建有IMG1这个字段.怎样实现IMG1这个字段的数据汇总.
如表:标题 内容 IMG1
xxx xxxxxx 123.jpg
gsa xxxxxx 235.jpg
sdf xxxxxx
gas xxxxxx 456.jpg
问题是:如何将IMG1字段提取最新的两条记录,并将相应的标题,内容和IMG1的值存入另外的变量中.
急盼解答
表没有自动编号,而且IMG1这一字段也不是每一个都有记录,有此是没有记录的
标题 内容 IMG1
xxx xxxxxx 123.jpg
gsa xxxxxx 235.jpg
sdf xxxxxx
gas xxxxxx
dff xxxxxx 793.jpg

你的表有自动编号的id没有,若有并且递增的话可以这样
strsql="select top 2 * from 表名 order by id desc"
set conn=server.createobject("adodb.connection")
set rst=server.createboject("adodb.recordset")
conn.connectionstring=sever.mappath(你的数据库路径)
conn.open()
rst.open strsql,conn,1,1
if not rst.eof then
title=rst.fields("标题")
content=rst.fields("内容")
img=rst.fields("img")
rst.movenext
title2=rst.fields("标题")
content2=rst.fields("内容")
img2=rst.fields("img")
end if
rst.close()
conn.close()
set rst=nothing
set conn=nothing

xxx xxxxxx 123.jpg
gsa xxxxxx 235.jpg
sdf xxxxxx
gas xxxxxx
dff xxxxxx 793.jpg