Writing From A dataset to a comma delimited text file

  • Thread starter Thread starter John Tyce
  • Start date Start date
J

John Tyce

Does any one know how to write the data from a dataset table to a text file? I have found a clumsy way to do it using WriteXml, XmlReader, XmlNodeReader, etc, but this seems awful clumsy. Is there a better way to do this?
 
John,

There is no way to do it out of the box. You will have to write the
file yourself (cycling through all columns for each row).

You ^might^ be able to do it using a text provider (I think that there
was one for OLEDB), but I am not sure that would work. Or perhaps, an ODBC
provider.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)



Does any one know how to write the data from a dataset table to a text file?
I have found a clumsy way to do it using WriteXml, XmlReader, XmlNodeReader,
etc, but this seems awful clumsy. Is there a better way to do this?
 
Hi John,

Here is the code I'm using , it comes from a PPC app and does exactly what you want :)

StreamWriter writer = new StreamWriter( Config.DataPath + "\\" + Config.OldOrdersFile, false);
writer.WriteLine("Tablename=OldOrders");
foreach(DataRow dr in _oldOrders.Tables[0].Rows )
{
StringBuilder builder = new StringBuilder( 200); // None row is bigger than this
foreach(object o in dr.ItemArray)
{

builder.Append( o.ToString() );
builder.Append( ',' );
}
builder.Remove( builder.Length-1, 1);
writer.WriteLine( builder.ToString() );
}
writer.Close();

Cheers,


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Does any one know how to write the data from a dataset table to a text file? I have found a clumsy way to do it using WriteXml, XmlReader, XmlNodeReader, etc, but this seems awful clumsy. Is there a better way to do this?
 
Back
Top