Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->编程语言 ->ASP ->正文

用表单来提交sql - 1

来源:Linuxdby.com 作者:Webmaster 时间:2007-04-23 点击: [收藏] [投稿]
<%
'从表单中提取值
fName = request.form("fName")
lName = request.form("lName")
age = request.form("age")

'建立SQL语句
iStr = "insert into uData (fName, lName, age) "
iStr = iStr & "values ("
iStr = iStr & "'" & fName & "', "
iStr = iStr & "'" & lName & "', "
iStr = iStr & age & ")"

if trim(fName <> "") then
         response.write( iStr & "<BR>")
else
%>

<html>
<body>
<form name=f method=post action="listing1.asp">
Gimme your:<br>
First Name: <input type=text name="fName"><br>
Last Name: <input type=text name="lName"><br>
Age: <input type=text name="age"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

<%
end if
  %>


列表 B:使用 request.form 来轻松建立SQL字符串。



<%
iStr = "insert into uData "
vStr = "values ("
nStr = "("

' 在表单集合中循环,并建立起SQL语句的组成部分
for each x in request.form
         ' 建立字段名列表
         nStr = nStr & x & ", "
         ' 建立字段值列表
         if uCase(x) = "AGE" then
                  vStr = vStr & request.form(x) & ", "
         else
                  vStr = vStr & "'" & request.form(x) & "', "
         end if       
next

' 把结尾的", " 从我们建立的字符串中去掉


vStr = left(vStr, len(vStr) - 2) & ")"
nStr = left(nStr, len(nStr) - 2) & ") "

' 把SQL语句组装起来
iStr = iStr & nStr & vStr

if trim(request("fName")) >> "" then
         response.write( iStr & ">BR>")
else
%>

<html>
<body>
<form name=f method=post action="列表2.asp">
Gimme your:<br>
First Name: <input type=text name="fName"><br>
Last Name: <input type=text name="lName"><br>
Age: <input type=text name="age"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

<%
end if
  %>







 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:用表单来提交sql - 2   下一篇:让您的主页支持各种浏览设备(ASP+篇)(上)

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号