这句Recordset关闭语句怎么错了?
我练习写个asp页面,测试ado的数据库更新操作。
页面的功能是这样的:后台有个数据库userinfo.mdb,有个userinfo表,字段设计是这样
tvid 文本
pwd 文本
logtime 文本
访问asp页的url是这样的:
http://gdutvrlabnet.h216.000pc.net/test/testSqlUpdate.asp?tvid=12345678&pwd=1234
(以上是个真实地址,大家可以试着访问下帮我测试下)asp页被访问时,从url取参数,检查tvid字段,如发现其值在数据库中没有,就加一个记录。如果发现数据库有了,就检查系统时间,把时间更新写到logtime字段中。
testSqlUpdate.asp代码如下
---------------------------------
<%@ Language=VBScript %><html><head> <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <title>New Page 1</title></head><body> <p>test ADO 更新语句</p> <% tvid = request("tvid") pwd = request("pwd") if tvid<>"" then Set Conn=Server.CreateObject("ADODB.Connection") Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;"&_ "Data Source="& Server.MapPath("userinfo.mdb") Conn.Open Set RS=Server.CreateObject("ADODB.Recordset") sql="select*from userinfo where tvid='"&tvid&"'" rs.open sql,conn,1,1 set rs1=server.createobject("ADODB.Recordset") if rs.EOF or rs.bof then rs1.Open "userinfo",conn,1,2 rs1.addnew array("tvid","pwd"), array(tvid,pwd) Response.Write "New user added: " + tvid + "(" + pwd + ")" else DateAndTime = getDate() 'Response.Write "aaa=" + DateAndTime sql1="Update userinfo set logtime=""" + DateAndTime + """ where tvid=""" + tvid + """" 'Response.Write sql1 rs1.open sql1,conn,1,2 rs1.close '问题在这句,注释掉这句网页就不出错了。 set rs1=nothing end if rs.close set rs=nothing set conn=nothing end if %> <% function getDate() getDate=year(now)&"-"&month(now)&"-"&day(now)&" "&hour(now)&":"&minute(now)&":"&second(now) end function %> </body></html>sql1 = "Update userinfo set logtime='" & DateAndTime & "' where tvid='" & tvid & "'" conn.execute sql1
[解决办法]
[color=#FF0000]sql="select*from userinfo where tvid='"&tvid&"'"[/color]
[解决办法]
不要设置成Recordset, 直接execute, 就如hookee 所说。。。 打开的方式不对,所以在close的时候当然出错
[解决办法]
update是不返回任何,要用execute去执行一下update语句。