您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
用表单来提交sql - 3
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:19:52
me="num_age"<<br>
<input type="checkbox" value="Y" name="MyCheckBox"<Do you want this checked?<br>
<input type="submit" value="Submit">
</form>
</body>
</html>

<%
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 & ", "
                                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)
                                              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("") & "<BR<")
         response.write( buildSQLInsert("NUM_AGE") & "<BR>")
         response.write( buildSQLInsert("lname,fname") & "<BR>")
         response.write( buildSQLInsert("mycheckbox,fname") &
         

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


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |