欢迎来到代码驿站!

DB2

当前位置:首页 > 数据库 > DB2

用表单来提交sql(转)3

时间:2020-10-17 23:30:27|栏目:DB2|点击:
正在看的db2教程是:用表单来提交sql(转)3。 列表 D: buildSQLInsert函数的最终版。


<%
function buildSQLInsert( targetTable, omitFields)
         iStr = "insert into " & targetTable & " "
         vStr = "values ("
         nStr = "("
          在表单集合中循环,并建立起SQL语句的组成部分
         for each x in request.form
                  fieldName = uCase(x)
                   判断字段是否被省略?
                  if inStr(uCase(omitFields),x) = 0 then
                       fieldData = replace(request.form(fieldName), _
                                "", "")
                        如果没有数据,就插入 NULL
                       if trim(fieldData) = "" then
                                fieldData = "NULL"
                                vStr = vStr & fieldData & ", "
                                nStr = nStr & fieldName & ", "
                       else
                                typeDelimPos = inStr(fieldName, "_")
                                if typeDelimPos = 0 then
                                      是文本字段
                                      建立字段名列表
                                     nStr = nStr & fieldName & ", "
                                     vStr = vStr &

[1] [2] [3] [4] [5] 下一页

正在看的db2教程是:用表单来提交sql(转)3。"" & 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       
&

上一页  [1] [2] [3] [4] [5] 下一页

正在看的db2教程是:用表单来提交sql(转)3。nbsp;                      end if
                  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")&request("lname")&request("age")) <> "" then
         response.write( buildSQLInsert("") & "
<")
         response.write( buildSQLInsert("NUM_AGE") & "
")
         response.write( buildSQLInsert("lname,fname") & "
")
         response.write( buildSQLInsert("mycheckbox,fname") &
         =<"
<")
else
%>




Gimme your:

First Name: <

Last Name: <

Age: <







<%
end if
  %>




列表 D: buildSQLInsert函数的最终版。


<%
function buildSQLInsert( targetTable, omitFields)
         iStr = "insert into " & targetTable & " "
         vStr = "values ("
         nStr = "("
          在表单集合中循环,并建立起SQL语句的组成部分
         for each x in request.form
                  fieldName = uCase(x)
                   判断字段是否被省略?
                  if inStr(uCase(omitFields),x) = 0 then
                       fieldData = replace(request.form(fieldName), _
                                "", "")
                        如果没有数据,就插入 NULL
                       if trim(fieldData) = "" then
                                fieldData = "NULL"
                                vStr = vStr & fieldData & ", "
        

上一页  [1] [2] [3] [4] [5] 下一页

正在看的db2教程是:用表单来提交sql(转)3。                        nStr = nStr & fieldName & ", "
                       else
                                typeDelimPos = inStr(fieldName, "_")
                                if typeDelimPos = 0 then
                                      是文本字段
                                      建立字段名列表
                                     nStr = nStr & fieldName & ", "
                                     vStr = vStr & "" & fieldData & ", "
                                else
                                      字段是其它类型
                                     fieldType = left(fieldName, typeDelimPos - 1)
                                     fieldName = mid(fieldName, typeDelimPos + 1)
                                      把字段名加入名称列表
                                     nStr = nStr & fieldName & ", "
                                      把字段类型变成大写以确保匹配
                                     select case uCase(fieldType)
                                        &n

上一页  [1] [2] [3] [4] [5] 下一页

正在看的db2教程是:用表单来提交sql(转)3。bsp;     case "NUM"
                                              vStr = vStr & fieldData & ", "
                                              把不明类型按文本型处理
                                              case else
                                              vStr = vStr & "" & fieldData & ", "
                                     end select
                                end if       
                       end if
                  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")&request("lname")&request("age")) <> "" then
         response.write( buildSQLInsert("") & "
<")
         response.write( buildSQLInsert("NUM_AGE") & "
")
         response.write( buildSQLInsert("lname,fname") & "
")
         response.write( buildSQLInsert("mycheckbox,fname") &
         =<"
<")
else
%>




Gimme your:

First Name: <

Last Name: <

Age: <







<%
end if
  %>

上一页  [1] [2] [3] [4] [5] 

上一篇:DB2编程序技巧 (七)

栏    目:DB2

下一篇:如何访问大型机、小型机上的DB2 9数据服务器

本文标题:用表单来提交sql(转)3

本文地址:http://www.codeinn.net/misctech/12915.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有