ASP基础实例教程之五个小时学会Asp连接access添加,删除,修改
(第一个小时)
1:首先建立一个access数据库保存为 xhnew.mdb 表名为aa
字段如下:
id 自动排序
name 文本
content 文本
xhtime 日期 默认值 now()
title 文本
2:打开DW 建立文件conn.asp文件
代码如下:
CODE:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("xhnew.mdb")
%>
这段语句是连接数据库的语句 set conn=server.createobject("adodb.connection")创建一个connection对象 用该对象的open方法打开数据库
driver={microsoft access driver (*.mdb)};这句语句是access的驱动
dbq="&server.mappath("xhnew.mdb")这句是数据库的路径
建立conn.asp是为了方便接下来的教学。。。
我们可以任何要用到打开数据库连接的文件里加
<!--#include file="conn.asp"-->就可以调用
是不是很方便。第一个小时就学这么多。。。当你弄明白上面的数据库还有代码后。。
就继续跟着我学吧!
(第2个小时)
现在来学把数据库的信息输出来
下面先建立一个主文件index.asp
代码如下
CODE:
<!--#include file="conn.asp"-->
<%
exec="select * from aa order by id desc "
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
%>
<table width="628" height="24" border="1" align="center" cellpadding="1" cellspacing="0">
<%
if rs.eof and rs.bof then
response.write("暂时没有文章")
else
do while not rs.eof
%>
<tr>
<td width="66" height="22" ><%=rs("id")%></td>
<td width="66" ><%=rs("name")%></td>
<td width="66" ><%=rs("content")%></td>
<td width="273" ><%=rs("xhtime")%></td>
<td width="53" ><%=rs("title")%></td>
<td><a href="modify.asp?id=<%=rs("id")%>" target="_self">编辑</a></td>
<td width="32" ><a href="del.asp?id=<%=rs("id")%>">删除</
五个小时学会Asp连接access添加,删除,修改
最新推荐文章于 2024-03-20 21:25:02 发布