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?
 
John,

Check this link out:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;306023

--
Patrick Altman
[Remove "JUST_SAY_NO_TO_SPAM" to send me email.]


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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top