<%
Dim mode
mode=request.form("tex±™∑™t4")
if mode=1 then
name=request.form("text1")
age=request.form("text2")
addr=request.form("text3"φ•)
if not isnumeric(age) then respε♣♦onse.write "age must be number!<a href=javascript:history.go(-1)>try again<÷₹;/a>":response.end
age=clng(age)
end if '*****************************************'™♥***************************
' 與AccessDB相(xiàng)關的(de)連接信息
' 可(kě)以參照(zhào)它建立您的(de)數(shù)據庫連接
'*****************************$✔'φ***************************************
Dim conn,rs,dbpath
Set conn=Server.CreateObject("ADODB.Connection")
Set rs=Server.CreateObject("ADODB≥ .RecordSet")
dbpath=Server.MapPath("rwd∏ata/db_test_com.mdb")
conn.Open "Driver={Micros™₽εoft Access Driver (*.mdb)}§; DBQ="&dbpath
'***********************************↕÷**********************®✘≥π***********
'**********************•∞********************************✘££**************
dim strsql
'**********************®€**********************************************
' 讀(dú)數(shù)據庫相(xiàng)關操作(zuò)
sub readdb()
strsql="select * from test"
rs.open strsql,conn,1,1
if rs.EOF then respons✔↑e.write "no record at all":exit s'§↕ub
response.write "<table border=÷₽1>"
response.write "<tr>"Ω£↕¶
for i=0 to rs.Fields.Count-1
response.write "<td><font color=blue&₽★≈¥gt;"&rs.Fields(i).Name&"</font&g↕λ♠≠t;</td>"
next
response.write "</tr>"
while not rs.EOF
response.write "<tr&≠γ↕gt;"
for i=0 to rs.Fields.Cε<'ount-1
response.write "<td>"&rs.Fi☆¶€™elds(i).value&"</td>"
next
response.write "</tr>"
rs.MoveNext
wend
response.write "</table>"
rs.Close
end sub
'************************************************♦σ********************
'**************************************** ±©****************************
' 寫數(shù)據庫相(xiàng)關
sub insertdata()
strsql="INSERT INTO test(na$α♣®me,age,addr) valueS('"&name&"',"&ag♥≤€∏e&",'"&addr&"')"
rs.Open strsql,conn,1,3
end sub
'***********************************************£♥↔≤*********************→φ
if mode=1 then
call insertdata()
response.write "insert ok!"
elseif mode=2 then
call readdb()
end if
'*********************************************₽***********************
' 釋放(fàng)數(shù)據庫連接對(duì)象
set rs=nothing
set conn=nothing
%>
<HTML>
<HEAD>
<TITLE></TI'¶TLE>
<script language=javascript>
function clickit(flag){
var form1=document.form2
form1.text4.value=flag;
if (flag==1){
if (form1.text1.value==""){
alert("name cant empty!");
return false;
}
if (form1.text2.value==""){
alert("age cant empty!");
return false;
}
if (form1.text3.value==""){
alert("addr cant empty$∞α"!");
return false;
}
}
form1.submit();
return true;
}
</script>
</HEAD>
<BODY>
<form method=post name=form2>
name:<INPUT type="text" id=text1 name=text®₩1 size=12>
age:<INPUT type="text"×∏§ id=text2 name=text2 size=12>
city:<INPUT type="text" id=text3 name=tex§"♠t3 size=12><br>
<INPUT type="hidden" id=text4 name=tex✘←t4>
<INPUT type="button" value="write" id=button1 name=button1 onclick="clickit(1)">
<INPUT type="button" ≈ ✘ value="read" id=button2 name=button2 onclick="clickit(2)">
</form>
</BODY>
</HTML>