怎么使ASP连接数据库...急急
开始的准备(连接一个DSN和ACCESS文件)和在ASP代码中的连接
具体操作.
再问个非技术的问题:用ASp做网站都得写代码吗?
------解决方案--------------------你是初学者吗?
建议看看下面的基础!
--------------------------------
ASP与数据库-连接、写入、修改、删除、显示代码分类:ASP学习
数据库连接
--------------------------------
MS Access数据库连接
用DSN连接并且没有用户名和密码:
<%
set conn=Server.CreateObject( "ADODB.Connection ")
conn.open "YourDSNName "
%>
用DSN连接并且有用户名和密码:
<%
set conn=Server.CreateObject( "ADODB.Connection ")
conn.open "YourDSNName ", "username ", "password "
%>
用实际的数据库绝对路径连接:
<%
Set conn=Server.CreateObject( "ADODB.Connection ")
Strconn= "DRIVER={Microsoft Access Driver (*.mdb)}; "
Strconn=Strconn & "DBQ=e:\yanhang\database.mdb "
conn.Open Strconn
%>
用实际的数据库相对路径连接:
<%
Set conn=Server.CreateObject( "ADODB.Connection ")
Strconn= "DRIVER={Microsoft Access Driver (*.mdb)}; "
Strconn=Strconn & "DBQ= " & Server.MapPath( "/database/yanhang.mdb ")
conn.Open Strconn
%>
MS SQL Server数据库连接
用DSN连接:
<%
set conn=Server.CreateObject( "ADODB.Connection ")
conn.open "DSN=MyDSN;UID=user;PWD=password;DATABASE=databasename "
%>
不用DSN连接:
<%
Set conn=Server.CreateObject( "ADODB.Connection ")
DSNtemp= "DRIVER={SQL Server};SERVER=ServerName;UID=USER;PWD=password;DATABASE=databasename "
conn.open DSNtemp
%>
Oracle数据库连接:
<%
set conn=server.createobject( "adodb.connection ")
conn.cursorlocation=adUseClient
DSNTemp= "Provider=MSDAORA.1;Password=xxxxx;User ID=yanhang;Data Source=xxx.world "
conn.open DSNtemp
%>
数据写入
……………………………………………………………………………………
<!--#i nclude file= "common/conn.asp "-->
<%
set rs=server.createobject( "adodb.recordset ")
sql= "select * from online "
rs.open sql,conn,3,2
rs.addnew
rs( "name ")=request( "name ")
rs( "Tel ")=request( "tel ")
rs( "fax ")=request( "fax ")
rs( "mail ")=request( "email ")
rs( "code ")=request( "zip ")
rs( "content ")=request( "contents ")
rs( "Address ")=request( "Address ")
rs.update
rs.close
%>
数据修改
……………………………………………………………………………………
<%
if request( "action ")= "edit " then '判断是否修改
'取得表单传递的数据
member_name=Trim(Request.Form( "member_name "))
member_pwd=Trim(Request.Form( "member_pwd "))
question=Trim(Request.Form( "question "))
answer=Trim(Request.Form( "answer "))
realname=Trim(Request.Form( "realname "))
sex=Trim(Request.Form( "sex "))
zip=Trim(Request.Form( "zip "))
address=Trim(Request.Form( "address "))
tel=Trim(Request.Form( "tel "))
fax=Trim(Request.Form( "fax "))
mobile=Trim(Request.Form( "mobile "))
email=Trim(Request.Form( "email "))
web=Trim(Request.Form( "web "))
vip=request.form( "vip ")
remark=Trim(Request.Form( "re