其中代码修改为以下内容,好像可以自动识别字段类型了,但不知实际使用会不会出错
sub Showsql(stable,coderType)
set rs=server.createobject("adodb.recordset")
rs.open "select * from "&stable&"",conn,1,1'==数据一定是存在的==
if coderType="add" then
fieldstr = ""
valuestr = ""
for i=1 to rs.fields.count - 1
T=rs.fields(i).name
P=rs.fields(i).type
if fieldstr="" then
fieldstr = T
else
fieldstr = fieldstr&","&T
end if
val = "trim(Request.Form("""&T&"""))"
if valuestr="" then
'2010-7-13 添加文本和备注字段识别 hp3325
if p=202 or p=203 then
valuestr = "'""&"&val&"&""'"
else
valuestr = """&"&val&"&"""
end if
'添加结束
else
'2010-7-13 添加文本和备注字段识别
if p=202 or p=203 then
valuestr = valuestr&","&"'""&"&val&"&""'"
else
valuestr = valuestr&","&"""&"&val&"&"""
end if
'添加结束
end if
next
Response.Write("insert into "&stable&" ("&fieldstr&") values ("&valuestr&")")
elseif coderType="update" then
fieldstr = ""
for i=1 to rs.fields.count - 1
T=rs.fields(i).name
P=rs.fields(i).type
val = "trim(Request.Form("""&T&"""))"
if fieldstr="" then
'2010-7-13 添加文本和备注字段识别
if p=202 or p=203 then
fieldstr
= T&"='""&"&val&"&""'"
else
fieldstr
= T&"=""&"&val&"&"""
end if
'添加结束
else
'2010-7-13 添加文本和备注字段识别
if p=202 or p=203 then
fieldstr
= fieldstr&","&T&"='""&"&val&"&""'"
else
fieldstr
= fieldstr&","&T&"=""&"&val&"&"""
end if
'添加结束
end if
next
Response.Write("update "&stable&" set "&fieldstr&" where "&rs.fields(0).name&"=""&"&rs.fields(0).name&"")
elseif coderType="del" then
Response.Write("delete from "&stable&" where "&rs.fields(0).name&"=""&"&rs.fields(0).name&"")
end if
end sub
'==sql形式代码处理==
[
本帖最后由 hp3325 于 2010-7-14 00:03 编辑 ]