用表单来提交sql - 3
2000-09-29 10:53:50 来源:WEB开发网核心提示:列表 D: buildSQLInsert函数的最终版,<%function buildSQLInsert( targetTable, omitFields) iStr = "insert into " & targetTable & " " vStr = "val
列表 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") &
=<"<BR<")
else
%>
<html>
<body>
<form name=f method=post action="列表4.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="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") &
=<"<BR<")
else
%>
<html>
<body>
<form name=f method=post action="列表4.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="checkbox" value="Y" name="MyCheckBox"<Do you want this checked?<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
<%
end if
%>
<%
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") &
=<"<BR<")
else
%>
<html>
<body>
<form name=f method=post action="列表4.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="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") &
=<"<BR<")
else
%>
<html>
<body>
<form name=f method=post action="列表4.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="checkbox" value="Y" name="MyCheckBox"<Do you want this checked?<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
<%
end if
%>
- ››SQL Server 2008 R2 下如何清理数据库日志文件
- ››sqlite 存取中文的解决方法
- ››SQL2005、2008、2000 清空删除日志
- ››SQL Server 2005和SQL Server 2000数据的相互导入...
- ››sql server 2008 在安装了活动目录以后无法启动服...
- ››sqlserver 每30分自动生成一次
- ››sqlite 数据库 对 BOOL型 数据的插入处理正确用法...
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
赞助商链接