Link to home
Start Free TrialLog in
Avatar of Kelly Martens
Kelly Martens

asked on

Text File as Data Source

Hey I am really struggling with this one. I can use a comma delimited file with no problem in my vb.net application I am building. But when I try to use a tab delimited file all I get is one column. The comma delimited worked. The rest did not. Can anyone tell me what I am doing wrong????

Dim Delimiter As String = ""
        If Me.cbDelimiter.Text = "," Then
            CSVConn.ConnectionString = ("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + Path.GetDirectoryName(FileName) + "; Extended Properties = ""Text;HDR=YES;FMT=Delimited""")
        End If
        If Me.cbDelimiter.Text = "|" Then
            CSVConn.ConnectionString = ("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + Path.GetDirectoryName(FileName) + "; Extended Properties=""text;HDR=YES;FMT=Delimited(|OrdersTAB.txtOrdersTAB.txt)""")
            ' Delimiter = "FMT=Delimited(|)"
        End If
        If Me.cbDelimiter.Text = "Tab" Then
            '= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDir;Extended Properties='text;HDR=YES;FMT=CSVDelimited;'; "
            'CSVConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FileName) + ";Extended Properties='text;HDR=YES;FMT=Delimited;'; "
            'CSVConn.ConnectionString = ("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + Path.GetDirectoryName(FileName) + "; Extended Properties=""text;HDR=YES;FMT=TabDelimited""")
            '  Delimiter = "FMT=TabDelimited"
            'CSVConn.ConnectionString = ("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + Path.GetDirectoryName(FileName) + "; Extended Properties = ""Text;HDR=YES;FMT=TabDelimited""")
            '    CSVConn.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" _
            '& Path.GetDirectoryName(FileName) &
            '";Extended Properties='text;HDR=YES;FMT=CSVDelimited'")
            ' CSVConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + Path.GetDirectoryName(FileName) + ";Extended Properties='text;HDR=YES;FMT=CSVDelimited;'; "
            CSVConn.ConnectionString = ("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + Path.GetDirectoryName(FileName) + "; Extended Properties = ""Text;HDR=YES;FMT=CSVDelimited""")

        End If
Orders1.csv
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kelly Martens
Kelly Martens

ASKER

Well seeing it has been as quiet as crickets on this question I am going to try your solution and let you know. I THINK since I am populating a datatable with this I should be able to replace

Do While Not tfp.EndOfData
            DataGridView1.Rows.Add(tfp.ReadFields())
        Loop

with the addrow function. I will let you know how it goes.
Your solution worked. But I am ashamed to admit.... I didn't review the data after I imported it from Access. It actually was bad data. At about line 65 it went like this:

10309      "HUNGO"      3      10/20/1994 0:00:00      11/17/1994 0:00:00      11/23/1994 0:00:00      1      $47.30      "Hungry Owl All-Night Grocers"      "8 Johnstown Road"      "Cork"      "Co. Cork"            "Ireland"
10310      "THEBI"      8      10/21/1994 0:00:00      11/18/1994 0:00:00      10/28/1994 0:00:00      2      $17.52      "The Big Cheese"      "89 Jefferson Way
Suite 2"      "Portland"      "OR"      "97201"      "USA"
10311      "DUMON"      1      10/21/1994 0:00:00      11/4/1994 0:00:00      10/27/1994 0:00:00      3      $24.69      "Du monde entier"      "67, rue des Cinquante Otages"      "Nantes"            "44000"      "France"


so the parsing would break no matter how we did it.

Irritated I spent 3 hours on this last night and didn't bother to check the data.

But thank you for your help sir. It is greatly appreciated.
Not a problem Kelly, always glad to help.