Save a Recordset to an ASCII file with custom field separators

  • Thread starter Thread starter Edward Grosso via .NET 247
  • Start date Start date
E

Edward Grosso via .NET 247

Hi to all the dotnet community,
I'm actually trying to figure out how can I save a Recordset to an ASCII file with custom field separators, in a fast way, without loops. Perhaps there is some way with a streamwriter object ?
Any idea ?
Thanks in advance
 
There is no "recordset" in ADO.NET. You could try to get the XML for these
date and transform using XSL.

Patrice

--

Edward Grosso via .NET 247 said:
Hi to all the dotnet community,
I'm actually trying to figure out how can I save a Recordset to an ASCII
file with custom field separators, in a fast way, without loops. Perhaps
there is some way with a streamwriter object ?
 
Apply XSLT on dataset/datatable XML, then you dont need to loop.

Thanks
Gerasha MCSD


Edward Grosso via .NET 247 said:
Hi to all the dotnet community,
I'm actually trying to figure out how can I save a Recordset to an ASCII
file with custom field separators, in a fast way, without loops. Perhaps
there is some way with a streamwriter object ?
 
Edward Grosso via .NET 247 said:
Hi to all the dotnet community,
I'm actually trying to figure out how can I save a Recordset to an ASCII
file with custom field separators, in a fast way, without loops. Perhaps
there is some way with a streamwriter object ?
Any idea ?

You realize that by "without loops" you mean "without loops that you write",
whatever method you choose will invariably be implemented by looping. So
you might as well just write it yourself.

public shared sub DumpDataTable(dt asDataTable, fileName as string)

dim outFile as new System.IO.StreamWriter("out.txt")

for each col as DataColumn in dt.Columns
if not firstCol then
outFile.Write("|")
firstCol = false
end if
outFile.Write(col.ColumnName())
next
outFile.WriteLine("")

for each row as DataRow in dt.Rows
dim firstCol as boolean = true
for each col as DataColumn in dt.Columns
if not firstCol then
outFile.Write("|")
firstCol = false
end if
outFile.Write(row(col).ToString())
next
outFIle.WriteLine("")
next

outFile.Close()

end sub
 
Back
Top