数据库连接
--------------------------------
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=pass
word;DATABASE=databasename"
conn.open DSNtemp
%>
FoxPro数据库连接
<%
Set Conn=Server.CreateObject("ADODB.connection")
ConnStr="Driver=Microsoft Visual Foxpro Driver; UID=userID;SourceType=DBC;SourceDB=C:\yanhang\database.dbc"
Conn.Open ConnStr
%>
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
%>
数据写入
……………………………………………………………………………………
<%
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
mark"))
sql="select * from member where m_id="&;m_id
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,3
rs("member_name")=member_name
rs("answer")=answer
rs("question")=question
rs("member_pwd")=member_pwd
rs("realname")=realname
rs("sex")=sex
rs("zip")=zip
rs("tel")=tel
rs("mobile")=mobile
rs("fax")=fax
rs("address")=address
rs("email")=email
rs("
web")=web
rs("vip")=vip
rs("remark")=remark
rs.update
rs.