Database export XML, HTM, CSV, SQL

xiaoxiao2021-03-06  76

<% 'Database exports record code' author Hawa, haiwa # blueidea.com, http://www.asp? SQL = SELECT Statement & TableName = Table Name (optional) & FileType = Export Format (XML, HTM, CSV, SQL) & PID = Auto Number field name (use only when exporting SQL type) DIM TABLENAME, FILETYPE, FIELDPIDSQL ??? = Request ("sql") TABLENAME? = Request ("TableName") FILETYPE? = LCASE ("FileType")) FieldPid? = Request ("pid") if FieldPid = "" "FieldPid =" ID "end iffieldpid = LCase (FieldPid) if Lcase (Left (SQL, 6)) <> "SELECT" TEN? response.write "SQL statement must be select * from [table] where ......."? Response.Endend IF

If Tablename = "" THEN TABLENAME = "Data Export Results" End IF

Function htmlencode (fstring)? if not isnull (fstring) Then ?? fstring = server.htmlencode (fstring) ?? fstring = replace (FString, CHR (10) & chr (10), "

") ?? fstring = replace (fstring, chr (10)," ") ?? fstring = replace (fstring, chr (9)," ""

?? htmlencode = fstring? End ifend function

Function MyReplace (STR)? IF not isnull (str) Then ?? fstring = replace (fstring, "" "" "" "") ?? myreplace = str? Else ?? myreplace = "" end ifend function

Function MyReplace2 (STR)? if not isnull (str) Then ?? fstring = replace (fstring, "'") ?? myreplace2 = str? Else ?? myreplace2 = "" "end ="

DIM DEF_EXPORT_SEP, DEF_EXPORT_VALDEF_EXPORT_SEP = "," DEF_EXPORT_VAL = "" "" "

SET RS = conn.execute (SQL) 'Export XML file if filetype = "xml" Then? Response.contettype = "text / xml"? Response.charset = "gb2312"? Response.addheader "Content-Disposition", "Attachment", "Attachment FILENAME = "& TableName &". Xml "? response.write" & vbnewline? response.write "

"

? Strline = ""

Dim Thefield (50)

? i = 0

? For? Each? X? In? Rs.fields

?? Thefield (i) = x.name

?? i = i 1

? Next?

? While rs.eof = false

? Strline = VBNewline & Chr (9) & "

"

? K = 0

? For? Each? X? In? Rs.fields

?? Strline =? Strline & vbnewline & chr (9) & chr (9) & "<" & thefield (k) & ">"

?? IF INSTR (X.Value, "<")> 0 or Instr (X.Value, ">")> 0 or inStr (x.value, "&")> 0 or Len (x.value)> 255 THEN

??? Strline =? Strline & ""

?? Else

??? Strline =? Strline & x.Value

?? endiff

?? Strline =? Strline & "

"

?? k = k 1

? Next?

? rs.movenext

? Response.Write Strline & Vbnewline & Chr (9) & "

"

Wend

Response.write vbnewline & "

"

'Export sql file elseif filetype = "sql" then Response.contenttype = "text / sql" Response.AddHeader "Content-Disposition", "attachment; filename ="?? & Tablename & ". Sql" strLine = "" dim sql_insert?? ? Each? X? IN? Rs.fields ?? if lcase (x.name) <> fieldpid then? 'If it is an automatic number ??? Strline =? Strline? & Def_export_val &? X.name & def_export_val & def_export_sep ?? End if? next? strline = replace (left (strline, len (strline) -1), "" "" "" ") strline =" INSERT INTO ["& TableName &" Values "? sql_insert = strline? 'response.write strline & vbnewline?' response.end? while =" "? e e p = =" '"for? Each? x? rs.fields ?? If LCASE (X.Name) <> FieldPid Then ??? '2004-8-11 Updating the NULL value that cannot be exported when the NULL value is not exported.

??? x_value = x.value ??? if isnull (x_value) or LEN (X_Value) = 0 THEN ???? x_value = "" ??? Else ???? x_value = replace (x_value, "'", "'") ????????????????? Strline =? Strline & DEF_EXPORT_VAL & X_VALUE & DEF_EXPORT_VAL & DEF_EXPORT_SEP ?? END IF? NEXT? RS.MOVENEXT? STRLINE = Left (Strline, Len (Strline) -1)? Response.write sql_insert & "(" & strLine & ") *" & vbnewline Wendelseif filetype = "csv" then Response.contenttype = "text / csv" Response.AddHeader "Content-Disposition", "attachment;??? filename = "& tablename &". csv "? strLine =" "? For? each? x? in? rs.fields ?? strLine =? strLine? & def_export_val &? x.name & def_export_val & def_export_sep? Next? Response.write strLine & vbnewline ? ?? Strline = "" ??? Each? X? In? Rs.fields ??? strline =? Strline & def_export_val & myreplace (x.value) & def_export_val& def_export_sep ?? next? rs.movenext ?? response.write strline & vbnewline? Wendelse? if filetype = "htm" the 'pops up the download of HTML dialog box ?? response.contenttype = "Application / MS-Downloader" ?? response.addheader "Content- Disposition "," Attachm Ent; filename = "& Tablename &". htm "? END IF%> Export data - www.51windows.net > Body, Input, SELECT ?????? {font-family: Tahoma; font-size: 8pt} TH ???????? {font-family: Tahoma; font-size: 8pt; padding: 3px; Color: #fffffff; background-color: # 999999;} TD ???????? {font-family: tahoma; font-size: 8pt; padding: 3px; Background-color: #efef;} ->

?

<% i = 0? for? Each? x? IN? rs.fields ?? Strline =? Strline? & chr (9) & chr (9) & "&? x.name? &" "& vbnewline? next? Response.Write Strline & Chr (9) & "

"& vbnewline & vbnewline? While = i 1 ?? Response.write chr (9) &"

"& vbNewline ?? Strline =" "?? for? Each? x? in? rs.fields ??? Strline =? Strline? & chr (9) & chr (9) &"

"&? Htmlencode (x.value) &" & vbnewline ?? NEXT ?? rs.movenext ?? response.write strline ?? Response.write chr (9) & "

"& VBNEWLINE & VBNEWLINE? WendResponse.write"

"& vbnewline

IF fileType <> "htm" and filetype <> "xls" and fileetype <> "sql"

Response.write "

"& I &" records Export HTML "Response.Write" | Export Excel "Response.Write" | Export XML "Response.Write" | Export SQL "& VBNewlineEnd IfResponse.write"

Power by http://www.51windows.net "" Target = "" _ blank "> 51windows.net" & vbnewlineresponse.write "

"& vbnewline

Response.write "& vbnewline"

Response.write "& vbnewline"

End ifrs.closeconn.closset RS = NothingSet Conn = Nothing%>


New Post(0)