Click here to Skip to main content
15,891,204 members
Articles / Web Development / IIS

Universal Table Editor

Rate me:
Please Sign up or sign in to vote.
4.86/5 (117 votes)
11 May 2003 1.6M   12.3K   275  
Viewer and Editor for any table in any Database you can reach from your IIS/PWS.
<%@ LANGUAGE = "VBScript" %>

<%
'***********************************************
'    UTE - (U)niversal ASP (T)able (E)ditor
'***********************************************
' UTE_EXPORT.ASP                       Rev.: 1.4
' Table export (csv) script     
'                                               
' (c) in 2000-2001 by Tom Wellige                    
' http://www.wellige.com , tom@wellige.com     
'                                               
' You may use and alter this script as long as  
' you put this original header in it !          
'                                               
'***********************************************
%>

<!--#include file ="ute.inc"-->

<%
   ' if not called from valid ute.asp session quit
   if Not Session("bValid") then
     WriteHTMLHeader "Export Error"
     Response.Write("Error: No Table specified !")
     WriteHTMLFooter
     Response.End
   else

     RequestParameter
     Set db = Session("db")
     Set rs = Session("rs")
     sTableName = Session("sTableName")

     ' set RecordSet to get all data
     rs.PageSize = rs.RecordCount
     rs.AbsolutePage = 1
     rs.MoveFirst

     ' get FileSystem Object
     Dim FSO
     Set FSO = Server.CreateObject("Scripting.FileSystemObject")

     ' calculate Filename
     Dim FileName
     FileName = sExportDir & UCase(sTableName) & "_" & CStr(Session.SessionID) & ".csv"

     Dim FilePath
     FilePath = Server.MapPath(FileName)

     ' create File
     Dim FileHandle
     Set fExport = FSO.CreateTextFile(FilePath, true)

     ' write Header
     sLine = ""
     if PrimaryKeyFieldsCount > 0 then
       for i = 1 to PrimaryKeyFieldsCount
         sLine = sLine & """" & PrimaryKeyFields(i) & ""","
       next
     end if 
     if StandardFieldsCount > 0 then
       for i = 1 to StandardFieldsCount
         sLine = sLine & """" & StandardFields(i) & ""","
       next
     end if 
     if sLine <> "" then
       sLine = Left(sLine, Len(sLine)-1)
       fExport.WriteLine(sLine)
     end if 

     ' write Data
     Do Until rs.EOF
       sLine = ""
       if PrimaryKeyFieldsCount > 0 then
         for i = 1 to PrimaryKeyFieldsCount
           sLine = sLine & """" & rs(PrimaryKeyFields(i)) & ""","
         next
       end if 
       if StandardFieldsCount > 0 then
         for i = 1 to StandardFieldsCount
           sLine = sLine & """" & rs(StandardFields(i)) & ""","
         next
       end if 
       if sLine <> "" then
         sLine = Left(sLine, Len(sLine)-1)
         fExport.WriteLine(sLine)
       end if 
       rs.MoveNext
     Loop
     
     ' close File
     fExport.Close

     ' send File to User
     Response.Redirect(FileName)

   end if

%>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
CEO Student
Germany Germany
Tom is in software development for about 15 years. He started with a SHARP MZ80k in Basic and Assembly Language. After collecting some experiance on an ATARI 1040ST he bought his very first IBM XT 286 (incl. 287!) and started to program in Turbo Pascal. He became very familiar with Borland's Turbo Vision and over the last years did a lot of development in C++ (MFC), Visual Basic, VB Script, ASP and SQL. He currently works as senior consultant for Swyx Solutions GmbH, based in Dortmund, Germany.
His absolute favourite is Guinness Wink | ;-) Sláinte!

Comments and Discussions