Make Www.Edu-cn.Com Your Home Page!
用户名: 密码: 验证码: 注册
  当前位置: > 中国教程网>数据库>DB2> 用表单来提交sql(转)2

用表单来提交sql(转)2

作者:   来源:中国教程网   点击:   日期:2007-04-02
列表 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) & ", "
AOE3 STUDIO

         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
%>




Gimme your:

First Name:

Last Name:

Age:






<%
end if
  %>



列表 C:把字段类型嵌入到HTML字段名中。


<%function buildSQLInsert( targetTable)         
iStr = "insert into " & targetTable & " "       edu-cn.com
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" www.edu4u.com.cn
                                vStr = vStr & fieldData & ", "
                                 把不明类型按文本型处理
                       case else
                                vStr = vStr & "" & fieldData & ", "
                       end select
                  end if        edu4u.com.cn
         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
%>




Gimme your:

First Name:

Last Name:

Age:




www.edu4u.com.cn

<%
end if
%>

www.edu-cn.com



文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   最新文章:
·用表单来提交sql(转)3(04-02)
·MySQL数据库结构和数据的导出和导入(04-02)
·常见数据库系统之比较 - DB2数据库(04-02)
·数据库复制技术在Internet上的实现(04-02)
·用表单来提交sql(转)3(04-02)
·DB2常用傻瓜问题1000问(之五)(04-02)
·将数据库中的数据通过client控件显示(04-02)
·用SQL Server为Web浏览器提供图像((04-02)
·IBM DB2 日常维护汇总(六)(04-02)
·Microsoft SQL Server 7.0 备份及恢(04-02)
   相关文章:
·用表单来提交sql(转)1 ·用表单来提交sql(转)3
·用SQL Server为Web浏览器提供图像(四)( ·用表单来提交sql(转)3
·用SQL Server为Web浏览器提供图像(三)( ·MySQL数据库结构和数据的导出和导入
·用SQL Server为Web浏览器提供图像(二)( ·常见数据库系统之比较 - DB2数据库
·用SQL Server为Web浏览器提供图像(一)( ·OSQL工具在DOS下的操作方式

   文章评论:(0条)
  
用户名: 新注册) 密码: 匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。

 §最新评论:

  责任编辑:中国教程网