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.O leDb.4.0; Data Source = " + Path.GetDirectoryName(File Name) + "; Extended Properties = ""Text;HDR=YES;FMT=Delimit ed""")
End If
If Me.cbDelimiter.Text = "|" Then
CSVConn.ConnectionString = ("Provider=Microsoft.Jet.O leDb.4.0; Data Source = " + Path.GetDirectoryName(File Name) + "; Extended Properties=""text;HDR=YES; FMT=Delimi ted(|OrdersTAB.txtOrdersTAB.txt)""")
' Delimiter = "FMT=Delimited(|)"
End If
If Me.cbDelimiter.Text = "Tab" Then
'= "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=C:\MyDir;Extended Properties='text;HDR=YES;F MT=CSVDeli mited;'; "
'CSVConn.ConnectionString = "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=" + Path.GetDirectoryName(File Name) + ";Extended Properties='text;HDR=YES;F MT=Delimit ed;'; "
'CSVConn.ConnectionString = ("Provider=Microsoft.Jet.O leDb.4.0; Data Source = " + Path.GetDirectoryName(File Name) + "; Extended Properties=""text;HDR=YES; FMT=TabDel imited""")
' Delimiter = "FMT=TabDelimited"
'CSVConn.ConnectionString = ("Provider=Microsoft.Jet.O leDb.4.0; Data Source = " + Path.GetDirectoryName(File Name) + "; Extended Properties = ""Text;HDR=YES;FMT=TabDeli mited""")
' CSVConn.ConnectionString = ("Provider=Microsoft.ACE.O LEDB.12.0; Data Source=" _
'& Path.GetDirectoryName(File Name) &
'";Extended Properties='text;HDR=YES;F MT=CSVDeli mited'")
' CSVConn.ConnectionString = "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source= " + Path.GetDirectoryName(File Name) + ";Extended Properties='text;HDR=YES;F MT=CSVDeli mited;'; "
CSVConn.ConnectionString = ("Provider=Microsoft.Jet.O leDb.4.0; Data Source = " + Path.GetDirectoryName(File Name) + "; Extended Properties = ""Text;HDR=YES;FMT=CSVDeli mited""")
End If
Orders1.csv
Dim Delimiter As String = ""
If Me.cbDelimiter.Text = "," Then
CSVConn.ConnectionString = ("Provider=Microsoft.Jet.O
End If
If Me.cbDelimiter.Text = "|" Then
CSVConn.ConnectionString = ("Provider=Microsoft.Jet.O
' Delimiter = "FMT=Delimited(|)"
End If
If Me.cbDelimiter.Text = "Tab" Then
'= "Provider=Microsoft.Jet.OL
'CSVConn.ConnectionString = "Provider=Microsoft.Jet.OL
'CSVConn.ConnectionString = ("Provider=Microsoft.Jet.O
' Delimiter = "FMT=TabDelimited"
'CSVConn.ConnectionString = ("Provider=Microsoft.Jet.O
' CSVConn.ConnectionString = ("Provider=Microsoft.ACE.O
'& Path.GetDirectoryName(File
'";Extended Properties='text;HDR=YES;F
' CSVConn.ConnectionString = "Provider=Microsoft.Jet.OL
CSVConn.ConnectionString = ("Provider=Microsoft.Jet.O
End If
Orders1.csv
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
Do While Not tfp.EndOfData
DataGridView1.Rows.Add(tfp
Loop
with the addrow function. I will let you know how it goes.