一个弱弱的问题,请高手看看这段代码哪错了

找找乐儿 2009-07-28 10:46:14
第一次写asp,很多语法都不会。我想实现在更新数据库的功能,具体是更新数据库的ID=(文本域1的内容),列名为单选框的值得数据为(文本域2的内容)。我是这样写的:
<%
dim id
dim lie
dim neirong
dim conn
dim sql
dim rs
set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="&Server.MapPath("/data/quertao.mdb")
set rs = Server.CreateObject("ADODB.Recordset")
%>
<form action="" method="post" name="form1" class="STYLE5" id="form1">
<label>输入ID
<input type="text" name="id" />
</label>
<label><br />
<br />
选择更行的列
<input type="radio" name="radiobutton" value="a" checked="on" />
a</label>
<label>
<input type="radio" name="radiobutton" value="b" />
b</label>
<label>
<input type="radio" name="radiobutton" value="c" />
c</label>
<label>
<input type="radio" name="radiobutton" value="d" />
d</label>
<label>
<input type="radio" name="radiobutton" value="e" />
e</label>
<label>
<input type="radio" name="radiobutton" value="f" />
f</label>
<p>
<label>输入更新内容
<input type="text" name="neirong" />
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
</p>
</form>
<%
id=request("id")
neirong=request("neirong")
lie=request("radiobutton")
sql= "update paihang set "&lie&"="&neirong&" where ID="&id&"" 数据表的名字叫paihang
rs.open sql,conn,1,3
rs.close
set rs=nothing
conn.close
set conn=nothing
%>

报告说update语法错误!我觉得好像是选择列名为复选框的值的列的时候出错了,但不知道怎么改,请高手帮忙!
...全文
108 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
找找乐儿 2009-07-30
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hookee 的回复:]
第一次显示的时候lei之类的事取不到值的,要递交后才行
字符类型的两边要单引号
VBScript code<%IfUCase(Request.ServerVariables("HTTP_METHOD"))="PSOT"Then
id=request("id")
neirong=request("neirong")
lie=request("radiobutton")
sql="update paihang set"& lie&"= '"& neirong&"' where ID="&id
conn.execute sql
conn.closeset conn=nothingEndIf
%>
[/Quote]

您好,我刚刚才发现,我按您说的改过,加上if里面的语句,的确是不报错了,但为什么更新语句不能更新数据库了?如果把if中的去掉,把“&lie&”换成具体的某一列名,是可以更新的!这是为什么啊?
hookee 2009-07-28
  • 打赏
  • 举报
回复
不需要转换呀,你用的是sql拼接的方式组成的sql字符串
假设id= 1,那么where ID=" & id 拼出来就是 where ID=1了
找找乐儿 2009-07-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 hookee 的回复:]
VBScript code
POST写错了,改一下<%IfUCase(Request.ServerVariables("HTTP_METHOD"))="POST"Then
id=request("id")
neirong=request("neirong")
lie=request("radiobutton")
sql="update paihang set"& lie&"=¡­
[/Quote]

恩,这个问题是明白了!现在我又有一个新的问题了,就是我的数据库里的ID列的类型是数字型的,我从表单中
id=request("id") 是字符型的,怎么才能将id转成响应的数字 即where ID=*id* 这个地方应该怎么写?
找找乐儿 2009-07-28
  • 打赏
  • 举报
回复
恩,这个问题是明白了!现在我又有一个新的问题了,就是我的数据库里的ID列的类型是数字型的,我从表单中
id=request("id") 是字符型的,怎么才能将id转成响应的数字 即where ID=*id* 这个地方应该怎么写?
hookee 2009-07-28
  • 打赏
  • 举报
回复

POST写错了,改一下
<%
If UCase(Request.ServerVariables("HTTP_METHOD")) = "POST" Then
id=request("id")
neirong=request("neirong")
lie=request("radiobutton")
sql= "update paihang set " & lie & "= '" & neirong & "' where ID="&id
conn.execute sql
conn.close
set conn=nothing
End If
%>
cpp2017 2009-07-28
  • 打赏
  • 举报
回复
1.确定你的表的列就是abcdef之一

2.内容要用'号


set "&lie&"='"&neirong&"' where ../
hookee 2009-07-28
  • 打赏
  • 举报
回复
第一次显示的时候lei之类的事取不到值的,要递交后才行
字符类型的两边要单引号

<%
If UCase(Request.ServerVariables("HTTP_METHOD")) = "PSOT" Then
id=request("id")
neirong=request("neirong")
lie=request("radiobutton")
sql= "update paihang set " & lie & "= '" & neirong & "' where ID="&id
conn.execute sql
conn.close
set conn=nothing
End If
%>

找找乐儿 2009-07-28
  • 打赏
  • 举报
回复
恩,现在知道了。。使用id=cint(id)先转一下就好了
  • 打赏
  • 举报
回复
用int(id)转换
找找乐儿 2009-07-28
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 hookee 的回复:]
不需要转换呀,你用的是sql拼接的方式组成的sql字符串
假设id= 1,那么where ID=" & id 拼出来就是 where ID=1了
[/Quote]
可是报错 说这个地方参数类型不匹配。我把我数据库中ID这一列的变成文本形式之后,就能够通过,但是我必须把ID这一列设置为数字型的,而从表单中得到的id是文本型的,所以会类型不匹配。

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧