国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

用表單來提交sql - 2

2019-11-18 22:17:25
字體:
供稿:網(wǎng)友
列表 B:使用 request.form 來輕松建立SQL字符串。

<%
iStr = "insert into uData "
vStr = "values ("
nStr = "("

' 在表單集合中循環(huán),并建立起SQL語(yǔ)句的組成部分
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

' 把結(jié)尾的", " 從我們建立的字符串中去掉
vStr = left(vStr, len(vStr) - 2) & ")"
nStr = left(nStr, len(nStr) - 2) & ") "

' 把SQL語(yǔ)句組裝起來
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 = "("    
' 在表單集合中循環(huán),并建立起SQL語(yǔ)句的組成部分
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
           ' 是另外一種數(shù)據(jù)類型
              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

         ' 把結(jié)尾的", " 從我們建立的字符串中去掉
         vStr = left(vStr, len(vStr) - 2) & ")"
         nStr = left(nStr, len(nStr) - 2) & ") "

         ' 把SQL語(yǔ)句組裝起來
         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
%>



發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 遵义县| 松江区| 兰坪| 南昌市| 循化| 泉州市| 洪雅县| 宁乡县| 宝清县| 剑河县| 长海县| 阳东县| 灵寿县| 隆安县| 冷水江市| 天峻县| 丹东市| 柏乡县| 旬阳县| 土默特右旗| 大竹县| 嘉黎县| 六枝特区| 广丰县| 介休市| 岳池县| 手机| 沙洋县| 交口县| 镇雄县| 安岳县| 都匀市| 红河县| 乌鲁木齐市| 凤翔县| 建始县| 凤台县| 阳高县| 秦安县| 琼海市| 离岛区|