'表的主键字段名
keyFieldName = request.Form("keyfield")
'用于过滤提交表单中的“'“的函数名
funQuote = request.Form("funQuote")
'表名
tableName = request("tableName")
If request.Form("subTable")<> "" Then
strSQL = "Select Top 1 * From " & tableName
set rsFields = Server.CreateObject("Adodb.recordset")
rsFields.open strSQL,conn,1,1
fieldsCount = rsFields.Fields.count
insertSQL = """INSERT INTO " & tableName & "("" & _" & vbCrlf
updateSQL = """UPDATE " & tableName & " SET "" & _" & vbCrlf
For i = 0 TO fieldsCount - 1
If INSTR(",3,202,203,","," & rsFields.fields(i).type & ",") > 0 AND Ucase(rsFields.fields(i).name) <> Ucase(keyFieldName) Then
iFields = iFields & """" & rsFields.Fields(i).name
Select case rsFields.fields(i).type
case 3 'INT
iDataFields = iDataFields & """"" & request.Form(""" & rsFields.fields(i).name & """) & """
updateSQL = updateSQL & """" & rsFields.Fields(i).name & "="" & request.Form(""" & rsFields.fields(i).name & """) & """
case 202 'CHAR
iDataFields = iDataFields & """'"" & " & funQuote & "(request.Form(""" & rsFields.fields(i).name & """)) & ""'"
updateSQL = updateSQL & """" & rsFields.Fields(i).name & "='"" & " & funQuote & "(request.Form(""" & rsFields.fields(i).name & """)) & ""'"
case 203 'TEXT
iDataFields = iDataFields & """'"" & " & funQuote & "(request.Form(""" & rsFields.fields(i).name & """)) & ""'"
updateSQL = updateSQL & """" & rsFields.Fields(i).name & "='"" & " & funQuote & "(request.Form(""" & rsFields.fields(i).name & """)) & ""'"
End Select
iFields = iFields & ", "" & _" & vbCrlf
iDataFields = iDataFields & ","" & _ " & vbCrlf
updateSQL = updateSQL & ","" & _ " & vbCrlf
End If
Next
iFields = Mid(iFields,1,len(iFields) - 9)
iDataFields = Mid(iDataFields,1,len(iDataFields) - 9)
insertSQL = insertSQL & iFields & ") VALUES ("" & _" & vbCrlf & iDataFields & ")"""
updateSQL = Mid(updateSQL,1,len(updateSQL) - 9) & """ & _ " & vbCrLf & """ WHERE " & keyFieldName & "="" & request.QueryString(""" & keyFieldName & """)"
End If
conn.close()
Set conn = Nothing
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>自动生成插入,修改SQL</title>
<style type="text/css">
body {
font-family: "宋体",Arial;
font-size: 9pt;
color: #0000FF;
background-color: #EEEEEE;
}
</style>
</head>
<body>
<form name="tableOpreate" action="?" method="post">
表名:<input name="TableName" type="text" id="TableName" value="product_research"><br>
关键字字段:<input name="keyField" type="text" id="keyField" value="pf_id"><br>
过滤“'”函数:<input name="funQuote" type="text" id="funQuote" value="fixQuote"><input name="subTable" type="submit" id="subTable" value="Submit"><br>
INSERT SQL:<BR><% response.Write("<textarea name=""textarea"" cols=""60"" rows=""10"">" & insertSQL & "</textarea><BR>")%>
UPDATE SQL:<BR><% response.Write("<textarea name=""textarea"" cols=""60"" rows=""10"">" & updateSQL & "</textarea><BR>")%>
</form>
</body>
</html>
本文地址:http://com.8s8s.com/it/it8154.htm