asp如何调用mdb内容
发布网友
发布时间:2024-10-10 19:00
我来回答
共4个回答
热心网友
时间:2024-10-17 00:08
<table width="300" height="190" border="0" cellspacing="0" cellpadding="0">
<%
dim conn
dim connstr
Set conn = Server.CreateObject("ADODB.Connection")
Connstr="DBQ="+server.mappath("book.mdb")+";DefaultDir='';DRIVER={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;ImplicitCommitSync=Yes;MaxBufferSize=512;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UserCommitSync=Yes;"
conn.Open connstr
'上面是连接数据库代码,可以在片头调用其它的.用别的代码段也行..
set rs = server.createobject("adodb.recordset")
sql = "select top 8 content from [book]"
rs.open sql,conn,1,1
if rs.eof then
else
do while not rs.eof
%>
<tr>
<td><%if len(rs("content"))>20 then%>
<%=left(rs("content"),20)%>..<%else%><%=rs("content")%><%end if%>
</td>
</tr>
<%
rs.movenext
loop
end if
rs.close
%>
</table>
热心网友
时间:2024-10-17 00:09
<%
dim conn
dim connstr
dim dbpath:dbpath="book.mdb" '这是数据库路径要是在文件夹(db)里 dbpath="db/book.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
Connstr="DBQ="+server.mappath(""&dbpath&"")+";DefaultDir='';DRIVER={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;ImplicitCommitSync=Yes;MaxBufferSize=512;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UserCommitSync=Yes;"
conn.Open connstr
'上面是连接数据库代码
set rs = server.createobject("adodb.recordset")
sql = "select top 8 content from book"
rs.open sql,conn,1,1
if rs.eof then
else
do while not rs.eof
if len(rs("content"))>20 then
response.write left(rs("content"),20)
else
response.write rs("content")
end if
rs.movenext
loop
end if
rs.close
%>
热心网友
时间:2024-10-17 00:09
要有一个300*190的页面,需要用window.open()方法,如果你要的话,我可以帮你写一个,也可以百度一下。
下面是关键的数据库遍历语句,我刚写的,可能没有错误,也可能有一点错误,自己调一下就好了,基本上原理是这样,相信你会
<%
SqlDataBase="***/BOOK.MDB"//这是数据库路径,自己改
ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" &Server.MapPath(SqlDataBase)
set Conn=Server.createobject("Adodb.connection")
Conn.open Connstr
If Err Then
Response.Write ""&IsSqlVer&"数据库连接出错,请检查连接字串。<br /><br />"&Err.Source&" ("&Err.Number&")"
Set Conn = Nothing
err.Clear
Response.End
End If
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open "Select * From [book]",Conn,3,1
If Not Rs.Eof Then
For i=1 To 8
Response.write Left(Rs("content"),20)
Rs.MoveNext
If Rs.Eof Then Exit For
Next
Rs.Close
Set Rs = Nothing
%>
热心网友
时间:2024-10-17 00:10
没人知道分就给我吧!可以为你家人添点祝福