MOTOBIT.COM - ASP upload, IIS utility SaveRS Method of DBF class

Method | Member of  RSConvert.DBF | Changes | Purchase | Download

Description

Saves the recordset as a DBF file

Syntax

DBF.SaveRS (FileName as String, RS as Variant, [FieldsFormat as String = From recordset])
 

Where Type Optional Default Description
 FileName  String     DBF file name 
 RS  Variant     ADO or DAO recordset to save 
 FieldsFormat  String  yes  From recordset  Format of field as array (see remarks) 

Remarks

Parameter FieldsFormat :
Array("Name1", "Type1", Size1, Decimal1,"Name2", "Type2", Size2, Decimal2 ...)
where
Name is name of the field
Type is DBF datatype, one of :
 C character
 N Numeric
 L Logical
 D Date
Size is field size for character and numeric fields
Decimal is number of decimal places for numeric fields

Examples

Save table from ADOSamples

  'Create Recordset and DBF objects
  Set ADORS = CreateObject("ADODB.Recordset")
  Set DBF = CreateObject("RSConvert.DBF")
  
  'Open table
  ADORS.Open "Customers", "DSN=ADOSamples"
  'Save table to the disk
  DBF.SaveRS "c:\dbfexport\Custo", ADORS
  'Close recordset
  ADORS.Close
  
  ADORS.Open "Products", "DSN=ADOSamples"
  DBF.SaveRS "c:\dbfexport\Products", ADORS
  ADORS.Close

Define exact DBF output format

Sub SimpleDBFTest()
  '1. Create simple recordset.

  Const adDate = 7
  Const adSingle = 4
  Dim RS: Set RS = CreateObject("ADODB.Recordset")
  RS.Fields.Append "Date", adDate
  RS.Fields.Append "Single", adSingle
  RS.Open
  AddDate RS, #1/1/1900#, 568.256
  AddDate RS, #1/1/1950#, 235.28
  AddDate RS, #1/1/1990#, 18.34
  AddDate RS, #1/1/1999#, 1234.58
  AddDate RS, #1/1/2000#, 1.25
  AddDate RS, #1/1/2020#, 4568.598
  AddDate RS, #1/1/2200#, 458774.23
  RS.MoveFirst

  Dim dbf 'As RSConvert.dbf
  
  '2. Create DBF object
  Set dbf = CreateObject("RSConvert.DBF")
  
  '3. get DBF as binary contents.
  Dim BinaryContents
  BinaryContents = dbf.GetFile(RS, , Array("DateField", "D", Empty, Empty, "NumField", "N", 4, 1))
  
  '4. Send the file to the client.
  Response.BinaryWrite BinaryContents

  RS.Close

End Sub

Sub AddDate(ByRef RS, ByVal D, N)
  RS.AddNew
  RS("Date") = D
  RS("Single") = N
  RS.Update
End Sub

Other links for SaveRS

Methods of DBF class

GetFile, SaveRS

Properties of DBF class

Compress, CurrencyDecimal, CurrencyWidth, DoubleDecimal, DoubleWidth, IntegerWidth, LongVarCharWidth, RowCount, SingleDecimal, SingleWidth, TempDirectory

RSConvert.DBF

Object for converting DAO or ADO recordset to the DBF file. It enables direct output of DBF files from the ASP page.

RSConvert

      Recordset converter is a library for converting DAO or ADO recordsets to MDB or DBF files. It enables direct binary output of MDB or DBF files from ASP pages with one row of code. The object also supports on-the-fly compression by zip/arj.

© 1996 - 2009 Antonin Foller, Motobit Software | About, Contacts | e-mail: info@pstruh.cz