前提:access数据库名为jishi.mdb,其中表名为news
1.asp连接access并显示具体内容:1.1 news_list.asp代码:<%
dim conn
set conn=server.CreateObject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};uid="";pwd="";dbq="&server.MapPath("jishi.mdb")
set rs=server.CreateObject("adodb.recordset")
sql="select * from news"
rs.open sql,conn,1,3do while not rs.eof
%>
"><%=rs("title")%> |
<%=rs("content")%> |
<%=rs("author")%> |
<%=rs("addtime")%> |
<%
rs.movenext
loop
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
1.2 news_view.asp代码:<%
id=request.QueryString("id")
dim conn
set conn=server.CreateObject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};uid="";pwd="";dbq="&server.MapPath("jishi.mdb")
set rs=server.CreateObject("adodb.recordset")
sql="select * from news where id="&id
rs.open sql,conn,1,3do while not rs.eof
%>
<%=rs("title")%> |
<%=rs("content")%> |
<%=rs("addtime")%> |
<%
rs.movenext
loop
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
2asp连接access数据库并发布新闻:2.1 news_add_code.asp代码:<%
title=trim(request.Form("title"))
author=trim(request.Form("author"))
content=trim(request.Form("content"))
dim conn
set conn=server.CreateObject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};uid="";pwd="";dbq="&server.MapPath("jishi.mdb")
set rs=server.CreateObject("adodb.recordset")
sql="select * from news"
rs.open sql,conn,1,3
rs.addnew
rs("title")=title
rs("content")=content
rs("author")=author
rs("addtime")=now()
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
response.Write("")
%>2.2 news_add.asp代码:
阅读(2272) | 评论(0) | 转发(0) |