更新数据库中的字段

来源:百度知道 编辑:UC知道 时间:2024/06/17 04:30:38
请问我有一个form值
<textarea name="checkyj"></textarea>
参数传递代码:
checkyj=trim(request.form("checkyj"))
if checkyj="" then
checkyj="k"
else
checkyj=checkyj
end if

现在想用checkyj值更新数据库中的checkyj字段,代码:
sql="update xleave set checkyj=checkyj where id="&id
为什么更新不了?
可能关键是参数传递问题,如果写成set checkyj='" & checkyj & "' 则无论你是否在form中输入内容,数据库中的字段都变成k了

checkyj=trim(request.form("checkyj"))
if checkyj="" then
checkyj="k"
else
checkyj=checkyj
end if
这段代码可以改成
checkyj=trim(request.form("checkyj"))
if checkyj="" then checkyj="k"

更新的话用:
sql="update xleave set checkyj='" & checkyj & "' where id="&id
是可以的

似乎还要详细点

vb r r akllkerlkal

这样肯定可以,我都这样写的
set rs = server.createobject("adodb.recordset")
sql = "select * from xleave where id="& id
rs.open sql,conn,1,3
if rs.eof then
response.write ""
else
rs("checkyj")=checkyj
rs.update
end if

最后的“="&id ”少空格,应为“=" & id ”原文中“checkyj=checkyj ”等号后面的“checkyj”是你的变量名吗?如是变量,全句应这样写:
sql="update xleave set checkyj='" & checkyj & "' where id=" & id