Solved

Read Tab Delimited text into dataset

Posted on 2007-11-26
1
3,325 Views
Last Modified: 2013-11-07
I have a tab delimited text file that I need to read into a dataset.  I have tried using Microsoft Jet OLEDB4.0 approach, which I can't seem to get to work and I also tried using a TextFieldParser, which almost worked, I was able to read a single row in.   An example of reading in tab delimited text into a dataset (datatable, whatever) using VB.net 2.0 would be greatly appreciated.  I have found a ton of examples on the web, however (at least so far) none of them have worked.

thanks,
0
Comment
Question by:clintnash
1 Comment
 
LVL 16

Accepted Solution

by:
gnoon earned 500 total points
Comment Utility
1. Create a folder to contains data files e.g. c:\data
2. Copy the tab delimited file(s) into the folder e.g. data.tab
    The file must contains only data, and no column names at the first line.
3. Create a file named schema.ini in the folder, and contains this information
      [data.tab]
      Format=TabDelimited
4. Write a program to read the file data.tab
Dim myConnection As New System.Data.OleDb.OleDbConnection( _

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\data;" & _

    "Extended Properties='text;FMT=TabDelimited;HDR=YES;'")

Dim myCommand As New System.Data.OleDb.OleDbCommand( _

    "SELECT * FROM data.tab", myConnection)

Dim sd As DataSet = New DataSet

Try

    myConnection.Open()

    Dim query As System.Data.OleDb.OleDbDataAdapter = _

	New System.Data.OleDb.OleDbDataAdapter(myCommand)

    query.Fill(sd)

    For Each r As DataRow In sd.Tables(0).Rows

	For Each o As Object In r.ItemArray

	    Console.Write(o & " ")

	Next

	Console.WriteLine()

    Next

Finally

    myConnection.Close()

End Try

Open in new window

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now