Results 1 to 2 of 2

Thread: How do I import a Tab Delimited Text File into a DataTable?

  1. #1

    Thread Starter
    Lively Member Christhemist's Avatar
    Join Date
    Sep 2016
    Location
    Nevada
    Posts
    116

    How do I import a Tab Delimited Text File into a DataTable?

    I am trying to import a tab delimited text file into a DataTable, but it does not appear to be splitting the columns properly. The code below does not error out but it also does not split up the data into the proper columns.

    Column Names Output
    First Last Address 1 Address 2 City State Zip
    F2
    F3
    F4
    F5
    F6
    F7

    As you can see in the above output, it is putting all the column names into the first column. I have highlighted the portion of my code I believe to be the issue. I have tried several different iterations of this, but everything has the same result.

    I've tried the following:
    Code:
    FMT=Delimited(" & vbtab & ")';
    Code:
    FMT=TabDelimited';
    Code:
    FMT=Delimited(Tab)';
    Here is my code so far:

    Code:
      Dim PathToUse As String = "C:\WORK\A_TEST\"
    
            Dim MyConnection As OleDbConnection
    
            Dim MyCommand As OleDbDataAdapter
    
            MyConnection = New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & PathToUse & "';Extended Properties='Text;HDR=Yes;FMT=Delimited(Tab)';") 
    
            MyCommand = New OleDbDataAdapter _
                    ("select * from [tab.txt]", MyConnection)
    
            MyCommand.Fill(AddressListDatatable)
    
            Dim Counter As Integer = 0
            For Each row In AddressListDatatable.Rows
                MsgBox(AddressListDatatable.Rows(Counter)(0).ToString)
                Counter = Counter + 1
            Next

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: How do I import a Tab Delimited Text File into a DataTable?

    You cannot specify that a file is Tab-delimited in the connection string. You can only specify that it is delimited. You specify that the delimiters are Tabs elsewhere, either in the Registry or a schema.ini file. Note that the first example here specifically mentions the Registry. You can find reference to a schema.ini file here.

    As an alternative, you could use a TextFieldParser and load the data into a DataTable yourself, which would allow you to avoid specifying the delimiter in a secondary location.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width