<%
Dim mode
mode=request.form("text4")
if mode=1 then
name=request.form("text1")
age=request.form("text2")
addr=request.form("text3")
if not isnumeric(age) the動器n response.write "age must be nu習紙mber!<a href=javascript:history.go(-1)>try again</a>廠物;":response.end
age=clng(age)
end if '*********************視鐵************************白很***********************
' 與AccessDB相關的連接信息
' 可以參照它建立您的數據庫連接
'********************道白************************************草少************
Dim conn,rs,dbpath
Set conn=Server.CreateObject("ADO如謝DB.Connection")
Set rs=Server.CreateObject(做朋"ADODB.RecordSet")
dbpath=Server.MapPath("r睡喝wdata/db_test_com.mdb")
conn.Open "Driver={Microsoft Access畫視 Driver (*.mdb)}; DBQ="&db為些path
'*************************************水票**********************城一*********
'**********************************綠近****************************月湖******
dim strsql
'*************************兒白***********************音視********************
' 讀數據庫相關操作
sub readdb()
strsql="select * from test"
rs.open strsql,conn,1,1
if rs.EOF then response.write "no 照時record at all":exit sub
response.write "<table bor林關der=1>"
response.write "<tr&g術相t;"
for i=0 to rs.Fields.Cou市村nt-1
response.write "<td><font col車服or=blue>"&rs.Fiel子兵ds(i).Name&"</font>&l日門t;/td>"
next
response.write "</坐月tr>"
while not rs.EOF
response.write "<tr>"
for i=0 to rs.Fields.Count-1
response.write "<td>"&身熱amp;rs.Fields(i).value&"</td>"
next
response.write "</tr>"
rs.MoveNext
wend
response.write "</慢河table>"
rs.Close
end sub
'*************************************花筆***********************唱和********
'**************************************子車*****************************畫子*
' 寫數據庫相關
sub insertdata()
strsql="INSERT INTO test(name,a土船ge,addr) valueS('"&name&"',"&age&",關唱'"&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
'************************************農爸************************生空********
' 釋放數據庫連接對象
set rs=nothing
set conn=nothing
%>
<HTML>
<HEAD>
<TITLE></TITLE>
<script language=javascript>
function clickit(fla我科g){
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&g跳日t;
name:<INPUT type="分不text" id=text1 name=t議國ext1 size=12>
age:<INPUT type="text" id=tex內黑t2 name=text2 size=12>
city:<INPUT type="tex匠愛t" id=text3 name=text3 size=12><b醫熱r>
<INPUT type="hidden" id=text4 name=草資text4>
<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>