473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 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 2461
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: EMW | last post by:
Hi, I have a CSV file where the fields are inclosed in " and separated by , i.e.: "field1","field2","field3",..... etc. Is it possible to fill a dataset in an easy way? I can write my own...
0
by: a | last post by:
I've read and split a delimited text file into a dataset. It looks fine in a datagrid (5 columns and 5,000 rows), but I've been trying, without success, to then insert the resulting dataset called...
0
by: TJS | last post by:
attempting to read a delimited text file into a dataset using oledb text file connection getting this error message when trying to open connection...
15
by: ruca | last post by:
Hi, Can I read a .TXT File to a DataSet? How can I do that? I want to read his lines to a DropDownList. This lines are the names of employees that I export from an application that I have. I...
4
by: washoetech | last post by:
Hello, I am working on a project where I need to be able to grab the data from an Excel spreadsheet and create a new table in my database based on the columns in the spreadsheet. After the...
3
by: Bruno | last post by:
Hi i try to import a .csv file to my dataset base but when i want used OleDbDataAdapter, i have error. my connection string : "Provider=Microsoft.Jet.OLEDB.4.0;" & _...
11
by: scorpion53061 | last post by:
Well I had a way to write an array to an excel spreadsheet but on a huge time critical run it failed iwth the dreaded HRESULT: 0x800A03EC error. It worked fine when i sampled the data to go in but...
4
by: Deepa | last post by:
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...
3
by: David P. Donahue | last post by:
I'm re-writing an application in C# that was originally written in Delphi 7. The heart of the application is a DataSet displayed in a DataGrid. One of the main functions of the previous...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.