建站代码网

热门标签

asp+Access编程常用代码

<%
'On Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("data/db.mdb")
conn.open connstr
%>


 


关闭数据库


 


<%
conn.close
set conn=nothing
%>
 


修改数据库信息


 


<%
'插入
sql="INSERT INTO branchtype (branchname,sj) VALUES ('"&branchname&"','"&now()&"')"
conn.execute(sql)


'修改
sql="update branchtype set branchname='"&branchname&"' where branchid="&clng(branchid)
conn.execute(sql)


'删除
sql="delete * from newslist where id="&id
conn.execute(sql)
 


读取数据库信息并显示


 


'无分页显示
sql="select branchname from branchtype where branchid="&branchid
set rs=conn.execute(sql)
if not rs.eof then
do while not rs.eof
response.write rs("branchname")&"<br/>"
rs.movenext
loop
else
response.write "对不起,没有数据"
end if
set rs=nothing

 


'分页显示
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
if not rs.eof then
rs.PageSize=16  '每页显示的数据条数
      page=request("page")
     if isnumeric(page)=false then
     page=1
     elseif page="" then
      page=1
      end if
     page=clng(page)
     if page>rs.pagecount then
     page=rs.pagecount
     end if
     rs.AbsolutePage=page
for i=1 to rs.pagesize
   if rs.eof or rs.bof then
   exit for
   end if
response.write rs("branchname")&"<br/>"


rs.movenext
next
if rs.pagecount>1 then
%>
<%if page<>1 then%> <a href=<%=webpage%>page=1 title=首页>首页</a><%else%><font color=dcdcdc>首页</font> <%end if%>
<%if page>10 then%> <a href=<%=webpage%>page=<%=page-10%> title=上十页>上十页</a><%else%><font color=dcdcdc>上十页</font> <%end if%>
<%if page>1 then%> <a href=<%=webpage%>page=<%=page-1%> title=上一页>上一页</a><%else%><font color=dcdcdc>上一页</font> <%end if%>
 共<%=rs.recordcount%>条数据  共<%=rs.pagecount%>页  当前第<%=page%>页
<%if page<rs.pagecount then%> <a href=<%=webpage%>page=<%=page+1%> title=下一页>下一页</a><%else%><font color=dcdcdc>下一页</font> <%end if%>
<%if page<rs.pagecount-10 then%> <a href=<%=webpage%>page=<%=page+10%> title=下十页>下十页</a><%else%><font color=dcdcdc>下十页</font> <%end if%>
<% if page<>rs.pagecount then%> <a href=<%=webpage%>page=<%=rs.pagecount%> title=末页>末页</a><%else%><font color=dcdcdc>末页</font> <%end if%>
<%
end if
else
response.write "对不起,没有数据"
end if
rs.close
set rs=nothing
%>

X