=======ASP连接查询access======
<%
option explicit
response.write("ASP连接查询access<hr size='1'>")
'ASP连接access
dim connstr,conn,db
db="db1.mdb"
set conn=server.createobject("adodb.connection")
connstr="provider=microsoft.jet.oledb.4.0;data source="&server.mappath(db)
conn.open connstr
'ASP查询access
dim rs,sql
sql="select * from table1"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
do while not rs.eof
response.write("姓名:"&rs("name")&" 工资:"&rs("pay")&"<br>")
rs.movenext
loop
'关闭清除对象
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
=======ASP连接查询sqlserver======
<%
option explicit
response.write("ASP连接查询sqlserver<hr size='1'>")
'ASP连接sqlserver
dim conn
conn="Provider=SQLOLEDB;Server=localhost;Database=database1;UID=sa;PWD=123"
'ASP查询sqlserver
dim rs,sql
sql="select * from table2"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
do while not rs.eof
response.write("姓名:"&rs("name")&" 工资:"&rs("pay")&"<br>")
rs.movenext
loop
'关闭清除对象
rs.close
set rs=nothing
set conn=nothing
%>
sqlserver连接中的用户名与密码“UID=sa;PWD=123”可自行修改。