473,383 Members | 1,877 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,383 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 2456
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.