GREEBA
asked on
Read a VBNet file using a tilde as deliminator instead of a comma
I would like to read a simple tilde deliminated file consisting of ten fields per record. In old fashioned basic we used to be able to specify the deliminator... How do I specify the deliminator in VBNet?
Thanks
Thanks
ASKER
Bob
.net Professional Version 2002
Thanks
.net Professional Version 2002
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks, Mikey. I was hoping for the opportunity to show delimited text parsing with 2005. Too bad, huh?
Bob
Bob
Lol...you itching for something to do today Bob?
Post it anways. =)
Post it anways. =)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Minor change for different delimiter:
reader.Delimiters = New String() {"~"}
Bob
reader.Delimiters = New String() {"~"}
Bob
Sweet...so many things to discover in .Net.
I myself had not encountered the TextFieldParser() class yet. =)
Thanx for sharing...
I myself had not encountered the TextFieldParser() class yet. =)
Thanx for sharing...
Or even one form, one button, one datagrid and this code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As DataTable = ReadFile("C:\Test", "tildesep.txt")
DataGrid1.DataSource = dt
End Sub
Private Function ReadFile(ByVal sourcepath As String, ByVal sourcefile As String) As DataTable
Dim ConStr As String = "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=" & sourcepath & ";Extended Properties=""text"";"
Dim SQL As String = "SELECT * FROM " & sourcefile
Dim Con As New OleDbConnection(ConStr)
Dim da As New OleDbDataAdapter(SQL, Con)
Dim dt As New DataTable
Try
da.Fill(dt)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dt
End Function
With a Schema.ini file, in the same directory as the sourcefile, containing
[tildesep.txt]
Format=Delimited(~)
Done in VB.NET 2003, but translates to 2005 OK.
Roger
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As DataTable = ReadFile("C:\Test", "tildesep.txt")
DataGrid1.DataSource = dt
End Sub
Private Function ReadFile(ByVal sourcepath As String, ByVal sourcefile As String) As DataTable
Dim ConStr As String = "Provider=Microsoft.Jet.OL
Dim SQL As String = "SELECT * FROM " & sourcefile
Dim Con As New OleDbConnection(ConStr)
Dim da As New OleDbDataAdapter(SQL, Con)
Dim dt As New DataTable
Try
da.Fill(dt)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dt
End Function
With a Schema.ini file, in the same directory as the sourcefile, containing
[tildesep.txt]
Format=Delimited(~)
Done in VB.NET 2003, but translates to 2005 OK.
Roger
Hellooooo, Roger dodger ;)
Bob
Bob
Hi all.
I see I missed the boat. Must have been closed whilst I was testing. ;-)
Roger
I see I missed the boat. Must have been closed whilst I was testing. ;-)
Roger
Bob