欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

asp 连数据库

shiping1 的头像

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>测试读取about表</title>
</head>

<body>
<%
'option explicit
'链接数据库
'dim conn,db,connstr    
'创建连接对象
Set conn = Server.CreateObject("ADODB.Connection")
'设置数据库位置
db="database/cdb.mdb"
'链接字符串
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
'这是数据库提供者的方式,使用其他方式总是不成功,所以还是只用这种方式好了,没有什么不好,我只是想多调试!
'conn对象的open方法
conn.Open connstr    
%>
<%
set rst=server.CreateObject("adodb.recordset")
sql="select * from about "
rst.open sql,conn,1,1
'if not rst.eof then response.Write(rst.recordcount)
do while not rst.eof
    response.Write(rst("id")&"&nbsp;&nbsp;"&rst("content")&"<br/>")
rst.movenext
loop
rst.close
set rst=nothing
%>
&nbsp;
</body>
</html>

 

 

 

下面这种连接方式 也是对的

<%

'define the public variable
dim system_name,title_name 'project name and the web title name
system_name="网站管理系统"
title_name="网站管理系统"

Server.ScriptTimeOut=900
'*******************************************************
'connection to the database
dim conn,rs,sql
set conn=Server.CreateObject("Adodb.Connection")
set rs=Server.CreateObject("Adodb.RecordSet")

dim dbpath  'the database path
dbpath=server.mappath("/") & "\db\cdb.mdb"
'response.write(dbpath)
'response.end

'connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath
connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & dbpath

conn.Open connstr

%>

普通分类: