程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> DB2數據庫 >> DB2數據庫綜合 >> 用表單來提交sql(轉)3

用表單來提交sql(轉)3

編輯: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] 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved