dim strsql'********************************************************************' 读数据库相关操作sub readdb()strsql="select * from test" rs.open strsql,conn,1,1if rs.EOF then response.write "no record at all":exit subresponse.write "<table border=1>"response.write "<tr>"for i=0 to rs.Fields.Count-1response.write "<td><font color=blue>"&rs.Fields(i).Name&"</font></td>"nextresponse.write "</tr>"while not rs.EOFresponse.write "<tr>"for i=0 to rs.Fields.Count-1response.write "<td>"&rs.Fields(i).Value&"</td>" nextresponse.write "</tr>"rs.MoveNextwendresponse.write "</table>"rs.Closeend sub'********************************************************************
'********************************************************************' 写数据库相关sub insertdata()strsql="INSERT INTO test(name,age,addr) VALUES('"&name&"',"&age&",'"&addr&"')"rs.Open strsql,conn,1,3end sub'********************************************************************
if mode=1 thencall insertdata()response.write "insert ok!"elseif mode=2 thencall readdb()end if
'********************************************************************' 释放数据库连接对象set rs=nothingset conn=nothing%><HTML><HEAD><TITLE></TITLE><script language=javascript>function clickit(flag){var form1=document.form2form1.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=text1 size=12>age:<INPUT type="text" id=text2 name=text2 size=12>city:<INPUT type="text" id=text3 name=text3 size=12><br><INPUT type="hidden" id=text4 name=text4><INPUT type="button" value="write" id=button1 name=button1 οnclick="clickit(1)"><INPUT type="button" value="read" id=button2 name=button2 οnclick="clickit(2)"></form></BODY></HTML>
转载于:https://www.cnblogs.com/fightLonely/archive/2010/10/14/1780894.html
