|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
帮助用户快速实现各种应用服务,ASP商有整合各方面资源的能力,可在短期内为用户提供所需的解决方案。例如,典型的ERP安装,如果要在客户端安装的话需要半年到二年的时间,但是美国的一些ASP商如USI和CORIO能在90—120天内提供ERP应用方案。xml|导出xml|数据|数据库|通用代码数据库导出xml、htm、csv、sql代码
用法:ExportDB.asp?sql=select语句&table=表名(可选)&filetype=导特别式(xml,htm,csv,sql)&pid=主动编号字段名(仅当导出sql范例时有效)
2004-8-11更新
<!--#includefile=../conn.asp-->
<%
数据库导出纪录代码
作者海娃,haiwa#blueidea.com,http://www.51windows.Net
用法:
ExportDB.asp?sql=select语句&tablename=表名(可选)&filetype=导特别式(xml,htm,csv,sql)&pid=主动编号字段名(仅当导出sql范例时有效)
dimtablename,filetype,fieldPid
sql=request("sql")
tablename=request("tablename")
filetype=lcase(request("filetype"))
fieldPid=request("pid")
iffieldPid=""then
fieldPid="id"
endif
fieldPid=lcase(fieldPid)
iflcase(left(sql,6))"select"then
Response.write"sql语句必需为select*from[table]where......."
Response.end
endif
<p>iftablename=""then
tablename="数据导出了局"
endif
functionHTMLEncode(fString)
ifnotisnull(fString)then
fString=Server.HTMLEncode(fString)
fString=Replace(fString,CHR(10)&CHR(10),"</P><P>")
fString=Replace(fString,CHR(10),"<BR>")
fString=Replace(fString,CHR(9),"")
HTMLEncode=fString
endif
endfunction
functionMyreplace(str)
ifnotisnull(str)then
fString=Replace(fString,"""","""""")
Myreplace=str
else
Myreplace=""
endif
endfunction
functionMyreplace2(str)
ifnotisnull(str)then
fString=Replace(fString,"","")
Myreplace2=str
else
Myreplace2=""
endif
endfunction
dimdef_export_sep,def_export_val
def_export_sep=","
def_export_val=""""
Setrs=Conn.Execute(sql)
导出XML文件
iffiletype="xml"then
Response.contenttype="text/xml"
Response.Charset="gb2312"
Response.AddHeader"Content-Disposition","attachment;filename="&tablename&".xml"
Response.write"<?xmlversion=""1.0""encoding=""gb2312""?>"&vbnewline
Response.write"<root>"
strLine=""
dimthefield(50)
i=0
Foreachxinrs.fields
thefield(i)=x.name
i=i+1
Next
Whilers.EOF=false
strLine=vbnewline&chr(9)&"<row>"
k=0
Foreachxinrs.fields
strLine=strLine&vbnewline&chr(9)&chr(9)&"<"&thefield(k)&">"
ifinstr(x.value,"<")>0orinstr(x.value,">")>0orinstr(x.value,"&")>0orlen(x.value)>255then
strLine=strLine&"<![CDATA["&x.value&"]]>"
else
strLine=strLine&x.value
endif
strLine=strLine&"</"&thefield(k)&">"
k=k+1
Next
rs.MoveNext
Response.writestrLine&vbnewline&chr(9)&"</row>"
Wend
Response.writevbnewline&"</root>"
导出sql文件
elseiffiletype="sql"then
Response.contenttype="text/sql"
Response.AddHeader"Content-Disposition","attachment;filename="&tablename&".sql"
strLine=""
dimsql_insert
Foreachxinrs.fields
iflcase(x.name)fieldPidthen假如是主动编号
strLine=strLine&def_export_val&x.name&def_export_val&def_export_sep
endif
Next
strLine=replace(left(strLine,len(strLine)-1),"""","")
strLine="insertinto["&tablename&"]("&strLine&")values"
sql_insert=strLine
Response.writestrLine&vbnewline
response.end
Whilers.EOF=false
strLine=""
def_export_val=""
Foreachxinrs.fields
iflcase(x.name)fieldPidthen
2004-8-11更新Null值时没法导出的bug。
x_value=x.value
ifisnull(x_value)orlen(x_value)=0then
x_value=""
else
x_value=replace(x_value,"","")
endif
strLine=strLine&def_export_val&x_value&def_export_val&def_export_sep
endif
Next
rs.MoveNext
strLine=left(strLine,len(strLine)-1)
Response.writesql_insert&"("&strLine&")*"&vbnewline
Wend
elseiffiletype="csv"then
Response.contenttype="text/csv"
Response.AddHeader"Content-Disposition","attachment;filename="&tablename&".csv"
strLine=""
Foreachxinrs.fields
strLine=strLine&def_export_val&x.name&def_export_val&def_export_sep
Next
Response.writestrLine&vbnewline
Whilers.EOF=false
strLine=""
Foreachxinrs.fields
strLine=strLine&def_export_val&Myreplace(x.value)&def_export_val&def_export_sep
Next
rs.MoveNext
Response.writestrLine&vbnewline
Wend
else
iffiletype="htm"then弹出下载html的对话框
Response.contenttype="application/ms-download"
Response.AddHeader"Content-Disposition","attachment;filename="&tablename&".htm"
endif
%>
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<METANAME="Author"CONTENT="51windows,海娃,haiwa">
<METANAME="Description"CONTENT="Powerby51windows.Net">
<title>导出数据-www.51windows.Net</title>
<style>
<!--
body,input,select{font-family:Tahoma;font-size:8pt}
th{font-family:Tahoma;font-size:8pt;padding:3px;color:#FFFFFF;background-color:#999999;}
td{font-family:Tahoma;font-size:8pt;padding:3px;background-color:#EFEFEF;}
-->
</style>
</head>
<BODYstyle="overflow:auto;"topmargin=2bgcolor=buttonface>
<formmethod="post"name=myform>
SQL:<inputtype="text"name="sql"value="<%=sql%>">
表名:<inputtype="text"name="tablename"value="<%=tablename%>"size="8">
导特别式:<selectsize="1"name="filetype">
<optionvalue="">请选择</option>
<option<%iffiletype="htm"thenResponse.write"selected"%>value="htm">htm</option>
<option<%iffiletype="xml"thenResponse.write"selected"%>value="xml">xml</option>
<option<%iffiletype="csv"thenResponse.write"selected"%>value="csv">csv</option>
<option<%iffiletype="sql"thenResponse.write"selected"%>value="sql">sql</option>
</select>
主动编号字段名:<inputtype="text"name="pid"value="<%=fieldPid%>"size="8"><inputtype="submit"value="断定">
</form>
<divalign="center">
<tableborder="0"cellpadding="0"cellspacing="1"bgcolor="#000000">
<tr>
<%
i=0
Foreachxinrs.fields
strLine=strLine&chr(9)&chr(9)&"<thalign=""center"">"&x.name&"</th>"&vbnewline
Next
Response.writestrLine&chr(9)&"</tr>"&vbnewline&vbnewline
Whilers.EOF=false
i=i+1
Response.writechr(9)&"<tr>"&vbnewline
strLine=""
Foreachxinrs.fields
strLine=strLine&chr(9)&chr(9)&"<td>"&HTMLEncode(x.value)&"</td>"&vbnewline
Next
rs.MoveNext
Response.writestrLine
Response.writechr(9)&"</tr>"&vbnewline&vbnewline
Wend
Response.write"</table>"&vbnewline
iffiletype"htm"andfiletype"xls"andfiletype"sql"then
Response.write"<pstyle=line-height:160%;>"&i&"笔记录<ahref=?tablename="&tablename&"&pid="&fieldPid&"&filetype=htm&sql="&server.urlencode(sql)&">导出HTML</a>"
Response.write"|<ahref=?tablename="&tablename&"&pid="&fieldPid&"&filetype=csv&sql="&server.urlencode(sql)&">导出EXCEL</a>"
Response.write"|<ahref=?tablename="&tablename&"&pid="&fieldPid&"&filetype=xml&sql="&server.urlencode(sql)&">导出XML</a>"
Response.write"|<ahref=?tablename="&tablename&"&pid="&fieldPid&"&filetype=sql&sql="&server.urlencode(sql)&">导出SQL</a>"&vbnewline
endif
Response.write"<p>Powerby<AHREF=""http://www.51windows.Net""target=""_blank"">51windows.Net</A>"&vbnewline
Response.write"</div>"&vbnewline
Response.write"</BODY>"&vbnewline
Response.write"</HTML>"&vbnewline
endif
rs.close
conn.close
Setrs=nothing
Setconn=nothing
%>
对于中小型web应用来说,php有很强的竞争力,linux+apache+mysql+php(lamp)的组合几乎可以胜任绝大多数网站的解决方案,对于大型应用来讲,对于系统架构要求更高,需要有成熟的框架支持,jsp的struts是个不错的框架,国内介绍它的资料也非常多,应用逐渐广泛起来。asp就不用说了, |
|