PC Review


Reply
Thread Tools Rate Thread

DataSet to a Tab delimited file

 
 
=?Utf-8?B?RGVlcGE=?=
Guest
Posts: n/a
 
      9th Mar 2005
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
 
Reply With Quote
 
 
 
 
Joshua Flanagan
Guest
Posts: n/a
 
      10th Mar 2005
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

 
Reply With Quote
 
=?Utf-8?B?Sm9iIExvdA==?=
Guest
Posts: n/a
 
      10th Mar 2005
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

 
Reply With Quote
 
=?Utf-8?B?RGVlcGE=?=
Guest
Posts: n/a
 
      10th Mar 2005
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

>

 
Reply With Quote
 
Joshua Flanagan
Guest
Posts: n/a
 
      11th Mar 2005
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

>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Load Text Tab Delimited File into a Dataset Ricardo.PT Microsoft Dot NET Framework Forms 1 12th Dec 2007 04:54 PM
delimited, but Non-Comma Delimited file, for input. Ross.prillaman@HCAhealthcare.com Microsoft Access External Data 1 15th Aug 2005 05:55 PM
Writing From A dataset to a comma delimited text file John Tyce Microsoft C# .NET 4 24th Aug 2004 01:55 PM
Filling a DataSet from a positionally delimited flat file billym Microsoft ADO .NET 2 16th Apr 2004 03:37 PM
fill dataset from reding a delimited text file TJS Microsoft ASP .NET 0 20th Dec 2003 08:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:03 AM.