数据库连接页面 conn.asp
<%
dim conn
dim connstr
on error resume next
connstr="DBQ="+server.mappath("db/data.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
%>
-------------------------------------------------------------------------------------------
<%
ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source ="&Server.MapPath("data/#data.mdb")
'On Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查链接字串。"
Response.End
End If
%>
-------------------------------------------------------------------------------------------
数据读取页面
<table width="642">
<%
set rs=server.CreateObject("adodb.recordset")
rs.open"select * from test order by hao_addtime desc",conn,1,1
if rs.eof or rs.bof then
response.write "<tr><td align=center>还没有任何数据。</td></tr>"
else
do while not rs.eof %>
<tr>
<td width="103"><div align="center"><%=rs("hao_id")%></div></td>
<td width="116"><div align="center"><%=rs("hao_name")%></div></td>
<td width="198"><div align="center"><%=rs("hao_note")%></div></td>
<td width="205"><div align="center"><%=rs("hao_addtime")%></div></td>
</tr>
<%rs.movenext
loop
rs.close
set rs=nothing
end if
%>
</table>