471,357 Members | 1,131 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,357 software developers and data experts.

DataSet to a Tab delimited file

Hi
I have a DataSet file (xml) which I need to convert it into a tab delimited
file. I need to write a C# console application for doing the same. Can anyone
help me out with the code to do it? I'd appreciate any kind of help.

Thanks
Jul 21 '05 #1
4 2357
Assuming you only have 1 table in the dataset, it should be as simple as:

int numColumns = ds.Tables[0].Columns.Count;
for(int row=0; row<ds.Tables[0].Rows.Count; rows++)
{
for(int col=0; col < numColumns - 1; col++)
{
writer.Write(ds.Tables[0].Rows[row][col].ToString() + '\t');
}
writer.WriteLine(ds.Tables[0].Rows[row][numColumns - 1].ToString());
}

Where:
ds = DataSet
writer = a type derived from TextWriter (example: StreamWriter is
probably your best bet)
Note - I make no claim that this is the fastest, most efficient method,
but it should do the job.

If you have more than one table in your dataset, you have to decide how
you want to handle the other tables - do they each get their own file?
Joshua Flanagan
http://flimflan.com/blog

Deepa wrote:
Hi
I have a DataSet file (xml) which I need to convert it into a tab delimited
file. I need to write a C# console application for doing the same. Can anyone
help me out with the code to do it? I'd appreciate any kind of help.

Thanks

Jul 21 '05 #2
this may help you

http://www.gotdotnet.com/Community/U...7-91c3f0cc973c
"Deepa" wrote:
Hi
I have a DataSet file (xml) which I need to convert it into a tab delimited
file. I need to write a C# console application for doing the same. Can anyone
help me out with the code to do it? I'd appreciate any kind of help.

Thanks

Jul 21 '05 #3
Joshua
Thanks for your reply. But my question is I basically have the dataset
itself. So when I say
int numColumns = ds.Tables[0].Columns.Count;
i guess it would give me an error about the ds.
The thing is am not getting the data from the database and filling the
dataset. Instead I have a response xml file which has the dataset itself. In
such case how do i populate the dataset ds?

Thanks
Deepa

"Joshua Flanagan" wrote:
Assuming you only have 1 table in the dataset, it should be as simple as:

int numColumns = ds.Tables[0].Columns.Count;
for(int row=0; row<ds.Tables[0].Rows.Count; rows++)
{
for(int col=0; col < numColumns - 1; col++)
{
writer.Write(ds.Tables[0].Rows[row][col].ToString() + '\t');
}
writer.WriteLine(ds.Tables[0].Rows[row][numColumns - 1].ToString());
}

Where:
ds = DataSet
writer = a type derived from TextWriter (example: StreamWriter is
probably your best bet)
Note - I make no claim that this is the fastest, most efficient method,
but it should do the job.

If you have more than one table in your dataset, you have to decide how
you want to handle the other tables - do they each get their own file?
Joshua Flanagan
http://flimflan.com/blog

Deepa wrote:
Hi
I have a DataSet file (xml) which I need to convert it into a tab delimited
file. I need to write a C# console application for doing the same. Can anyone
help me out with the code to do it? I'd appreciate any kind of help.

Thanks

Jul 21 '05 #4
Now you have me confused.

I guess you are saying you do NOT have an instance of a
System.Data.DataSet class.
You only have an XML file, which contains a SET of DATA - which has
nothing to do with System.Data.DataSet. Is that correct?

If that is the case, you could try creating an XSLT to transform the XML
input to tab-delimeted output. Look for some XSL transofmration tutorials.
How does an xml

Deepa wrote:
Joshua
Thanks for your reply. But my question is I basically have the dataset
itself. So when I say
int numColumns = ds.Tables[0].Columns.Count;
i guess it would give me an error about the ds.
The thing is am not getting the data from the database and filling the
dataset. Instead I have a response xml file which has the dataset itself. In
such case how do i populate the dataset ds?

Thanks
Deepa

"Joshua Flanagan" wrote:

Assuming you only have 1 table in the dataset, it should be as simple as:

int numColumns = ds.Tables[0].Columns.Count;
for(int row=0; row<ds.Tables[0].Rows.Count; rows++)
{
for(int col=0; col < numColumns - 1; col++)
{
writer.Write(ds.Tables[0].Rows[row][col].ToString() + '\t');
}
writer.WriteLine(ds.Tables[0].Rows[row][numColumns - 1].ToString());
}

Where:
ds = DataSet
writer = a type derived from TextWriter (example: StreamWriter is
probably your best bet)
Note - I make no claim that this is the fastest, most efficient method,
but it should do the job.

If you have more than one table in your dataset, you have to decide how
you want to handle the other tables - do they each get their own file?
Joshua Flanagan
http://flimflan.com/blog

Deepa wrote:
Hi
I have a DataSet file (xml) which I need to convert it into a tab delimited
file. I need to write a C# console application for doing the same. Can anyone
help me out with the code to do it? I'd appreciate any kind of help.

Thanks

Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by EMW | last post: by
15 posts views Thread by ruca | last post: by
11 posts views Thread by scorpion53061 | last post: by
4 posts views Thread by Deepa | last post: by
3 posts views Thread by David P. Donahue | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.