列表 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
%>
列表 c:把字段类型嵌入到html字段名中。
<%function buildsqlinsert( targettable)
istr = "insert into " & targettable & " "
vstr = "values (" nstr = "("
' 在表单集合中循环,并建立起sql语句的组成部分
for each x in request.form
fieldname = x
fielddata = replace( request.form(fieldname), "'", "''")
typedelimpos = instr(fieldname, "_")
if typedelimpos = 0 then
' its a text field
' 建立字段名列表
nstr = nstr & fieldname & ", "
vstr = vstr & "'" & fielddata & "', "
else
' 是另外一种数据类型
fieldtype = left(fieldname, typedelimpos - 1)
fieldname = mid(fieldname, typedelimpos + 1)
' 把字段名加入字段名列表中
nstr = nstr & fieldname & ", "
' 把字段类型变成大写,以确保匹配
select case ucase(fieldtype)
case "num"
vstr = vstr & fielddata & ", "
' 把不明类型按文本型处理
case else
vstr = vstr & "'" & fielddata & "', "
end select
end if
next
' 把结尾的", " 从我们建立的字符串中去掉
vstr = left(vstr, len(vstr) - 2) & ")"
nstr = left(nstr, len(nstr) - 2) & ") "
' 把sql语句组装起来
buildsqlinsert = istr & nstr & vstr
end function
if trim(request("fname")) >< "" then
response.write( buildsqlinsert & ">br<")
else
%>
<html>
<body>
<form name=f method=post action="listing3.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="num_age"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
<%
end if
%>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器