write database tables to text file

jllydgnt
02-09-2004, 12:48 PM
I am trying to write the contents of a database to text files. Basically, I want to write each table to its own text file.

To do this, I have a generic function set up that will take the name of the table and open a recordset based on that table's name. It will then loop through the recordset writing each record as a line in a text file. The problem I have is that I need to dynamically determine how many fields are in each table and get all of the fields in a record written to the same line in the text file.

My understanding is that each time you use the write statement, it starts a new line. So I cannot loop through the field count using a seperate write statement for each field. Is there some kind of statement or function that will simply append text to the last write statement? Or a way to prevent the write statement from creating a new line when it is called?

jllydgnt
02-09-2004, 01:13 PM
I am thinking that I will have to use a temporary string variable. Then loop through each field in the record and concatenate it to the string variable. Then use the write statement to write the string variable to the file. Any other ideas?

John
02-09-2004, 01:54 PM
That is what I would have suggested. Don't write to the file until you have a complete line to feed the write statement.

clafarge
02-10-2004, 04:25 PM
Take a look ADO Rercordset's "GetString (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthgetstringmethod(recordset)ado.asp) " method. Using:myRecordset.GetString(2) returns columns separated by vbTab and records separated by vbNewLine... same as doing this:field1Value & vbTab & field2Value & vbTab & field3Value & vbNewLine & _
field1Value & vbTab & field2Value & vbTab & field3Value & vbNewLine

And it's MUCH faster than looping through records (this coming form ASP experience).

Hope this helps.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum