asp连接数据库代码实例(2)
发布时间:2021-06-06
发布时间:2021-06-06
asp 连接数据库代码实例
2。增加纪录
<%
if request(\"action\")=\"add\" then
name=request.form(\"name\")
content=request.form(\"content\")
set rs=server.createobject(\"adodb.recordset\")
sql=\"select * from biao\"
rs.open sql,conn,3,2
rs.addnew
rs(\"name\")=name
if content<>\"\" then
rs(\"content\")=content
else
rs(\"content\")=null
end if
rs(\"date\")=date()
rs.update
rs.close
set rs=nothing
response.write \"<script language=javascript>alert(\'
\');location.href(\'index.asp\');</script>\"
end if
%>
--------------------------------------
3.显示记录
<%
set rs=server.createobject(\"adodb.recordset\")
sql=\"select * from biao order by id desc\"
\'sql=\"select top 10 * from biao order by id desc\"
rs.open sql,conn,1,1
rs.pagesize=15 \'-------设置每页显示的记录数
dim page
page=request(\"page\")
if page<>\"\" and IsNumeric(page) then
page=clng(page)
else
page=1
end if
n=rs.pagecount
if page>n then 添加成功!