473,385 Members | 1,730 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,385 software developers and data experts.

Reading tab delimited file

I have a file that is tab delimited and has no header row with column
headings. What is the best method for reading this data into a dataset?
Nov 16 '05 #1
1 42890
Hello John,

Here is some sample code that should get you started:

Expand|Select|Wrap|Line Numbers
  1. DataTable dt = new DataTable();
  2. using (TextReader tr = File.OpenText("TabDelimitedFile.txt"))
  3. {
  4. string line;
  5. while ((line = tr.ReadLine()) != null)
  6. {
  7. string[] items = line.Split('\t');
  8. if (dt.Columns.Count == 0)
  9. {
  10. // Create the data columns for the data table based on the number of items
  11. // on the first line of the file
  12. for (int i = 0; i < items.Length; i++)
  13. dt.Columns.Add(new DataColumn("Column" + i, typeof(string)));
  14. }
  15. dt.Rows.Add(items);
  16. }
  17. }
  18.  
  19. // Print out all the values
  20. foreach (DataRow dr in dt.Rows)
  21. {
  22. foreach (string s in dr.ItemArray)
  23. Console.Write(s + "\t");
  24. Console.WriteLine();
  25. }

HTH
Wes Haggard
http://weblogs.asp.net/whaggard/

"John Beavers" wrote:
I have a file that is tab delimited and has no header row with column
headings. What is the best method for reading this data into a dataset?
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Job Lot | last post by:
I have tab delimited text file which gets populated on daily basis via automated process. New entry is written at the bottom. I need to create a utility which makes a copy of this file with 10 most...
1
by: John B. Lorenz | last post by:
I'm attempting to write an input routine that reads from a comma delimited file. I need to read in one record at a time, assign each field to a field array and then continue with my normal...
4
by: Hilary Cotter | last post by:
Thanks for all the help you gave me yesterday. here is another question. I have a comma delimited file called redirect.txt which looks like this test, /test.htm test 123,/test123.htm
1
by: ungvichian | last post by:
So, right now I'm writing a program in VC++.Net with MFC, and one of the steps involves reading numeric values from a comma delimited file (like 4.56, 2.44, 3.453 etc.). The only methods I've been...
1
by: svijay | last post by:
hi I have got a strange problem. May I know any solution for this. Here is the detailed description about the problem We have got a mainframe system and also production and development...
6
by: =?Utf-8?B?UmljaA==?= | last post by:
'--this code works but only reads text into one column when contains multiple cols Dim ds1x As New DataSet Dim ConStr As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data...
1
jwwicks
by: jwwicks | last post by:
Hello All, This is a student assignment. So I don't want the complete answer just a hint or maybe a bumb on the head cause I'm doing it the wrong way. Assume I haven't done anything braindead like...
2
by: tshad | last post by:
I have a program that is reading a csv file into a dataset. I want it to read the 1st line as data. But it ignores it. I have the Connection set up as: OleDbConnection csvConnection = new...
1
by: yesvee | last post by:
Hello All, I'm new for Python programming and I'm having some issues parsing a delimited text file. Any help, suggestions and advice is really appreciated. Thanks a lot in advance. ...
20
by: cowboyrocks2009 | last post by:
Hi, I need help to automate my code to take data from input file. Also I need to create it as a function so that I can pass it to some other program. I am new to Java so having a bit limitation to...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.