• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3358
  • Last Modified:

Read Tab Delimited text into dataset

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
clintnash
Asked:
clintnash
1 Solution
 
gnoonCommented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now