Datatable to Tab Delimited Text file

  • Thread starter Thread starter RSH
  • Start date Start date
R

RSH

Hi,

I have a situation where I am querying SQL Server and bringing back a
Dataset. Is there a way to dump the datatable to a delimited text file
without iteration through the datatable?

The reason i need to do this is I am having to traverse a large number of
databases and the with iteration the process is taking quite a long time.

Thanks in advance!
Ron
 
I propose that you use DTS for this activity instead.

However,

In the past, I have dumped the xml of a datatable into a stringbuilder, and
executed a series of replace statemements. Finally, I iterate over the
columnnames of the table and insert them at the beginning of the string
builder for the row header.

Hope that helps.

<Newtable>
<datarow><Column1>Blah</Column1><Column2>Blah1</Column2></datarow>
</Newtable>

becomes
"Column1","Column2"
"Blah","Blah1"
 
There are of course other ways to go.

Instead of populating a datatable, which would be discarded anyway. Use a
DataReader and just stream the results into a text file on the fly. Perhaps
this would have the lowest impact on resources and time.
 
Back
Top