WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADO DAO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Generic Recordset to Text file UDF


;/////////////////////////////////////////////////////////
;// Generic Recordset-to-Text file UDF
;// Uses the ADO GetString() Method for conversion
;// This avoids time-consuming While loops
;//
;// accepts RS   - a valid ADO recordset
;//         file - a fully pathed csv file[name] to create
;//         hdrs - how to handle csv headers
;//              a. NONE
;//              b. RS
;//              c. header string (for your own with @CRLF)
;//         delm - delimiter (or "" for default)
;//
;// Example Usage:
;//         cFile = StrCat(dirget(),"temp.txt")
;//         adoRS2TXT( RS,cFile,"RS",@TAB )
;//         ( creates Tab-Delimited file with headers )
;//
;// stan littlefield
;/////////////////////////////////////////////////////////
#DefineFunction adoRS2TXT( RS,file,hdrs,delm )
delim = delm
If delim=="" Then delim=","  ;default
hdr   = ""
If hdrs == "NONE" Then Goto getstrng
If hdrs == "RS" Then Goto RS
hdr = hdrs
Goto getstrng
:RS
flds  = RS.Fields()
n = (flds.Count)-1
For i=0 To n
   If i == n Then delim = ""
   fld = RS.Fields(i)
   hdr = StrCat(hdr,fld.name,delim)
Next
hdr = StrCat(hdr,@CRLF)
ObjectClose(fld)
ObjectClose(flds)

:getstrng
data = RS.GetString(2,-1,delim,@CRLF,"")
FilePut(file,StrCat(hdr,data)
Return(FileExist(file))
#EndFunction
;/////////////////////////////////////////////////////////

Article ID:   W16080
File Created: 2004:03:30:15:42:46
Last Updated: 2004:03:30:15:42:46