Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > How to escape double quotes (") in tab delimited text file ? Urgent - please any idea is welcome
 

How to escape double quotes (") in tab delimited text file ? Urgent - please any idea is welcome

Hi

I am importing a tab delimited text file to access table. All works fine except some of the columns ofsome of the rows in the file not come up when I use the 'select command' . Becasue the rows have " (double quotes). Please some one help me how to escape these character.

I am using the following

1. Filessystemevents ' when file created in to folder this events kicks and do the following

2. Open connection to tab delimited text file

3. Using schema.ini ' contents are - [or455580090229.txt] Format = tabdelimited columnheader = true

3. 'Select command' to get the data from file

4. Datareader to read the data

5. While read loading the data in to variable

6. Insert to access table.

Advance thanks

Note : I couldn't paste the code here bcos it is my office pc.

Karan_vaish  Thursday, February 21, 2008 7:51 PM

Code Snippet

Private Sub doProcess()

Dim dt As DataTable = New DataTable()

Dim dr As DataRow

Dim tr As TextReader

Dim colString As String

Try

tr = File.OpenText("Path to my file")

Do

colString = tr.ReadLine()

If Not colString Is Nothing Then

Dim items As String() = colString.Split("\t")

dr = dt.NewRow()

dr(0) = items(0)

dr(1) = items(1)

'etc...

dt.Rows.Add(dr)

End If

Loop While Not colString Is Nothing

Catch e As Exception

'error process here.

End Try

'Update rows in Access from data set here

End Sub

Hope this helps...

jbaird-pa  Friday, February 22, 2008 4:35 PM

Read the file string by string using a textreader. If you're processing the file yourself, the extra " doesn't matter.

or

Doesn't access have an import file mechanism built in?

Hope this helps...

jbaird-pa  Friday, February 22, 2008 4:00 AM

Hi

Thanks for reply. Manual import to access works fine. I need to do this automaticaly when new file created- this also works fine except the double quotes.

How do I use text reader to read tab delimited and asign the each column's data to variables. Please give some code sample

Karan_vaish  Friday, February 22, 2008 9:32 AM

Code Snippet

Private Sub doProcess()

Dim dt As DataTable = New DataTable()

Dim dr As DataRow

Dim tr As TextReader

Dim colString As String

Try

tr = File.OpenText("Path to my file")

Do

colString = tr.ReadLine()

If Not colString Is Nothing Then

Dim items As String() = colString.Split("\t")

dr = dt.NewRow()

dr(0) = items(0)

dr(1) = items(1)

'etc...

dt.Rows.Add(dr)

End If

Loop While Not colString Is Nothing

Catch e As Exception

'error process here.

End Try

'Update rows in Access from data set here

End Sub

Hope this helps...

jbaird-pa  Friday, February 22, 2008 4:35 PM

You can use google to search for other answers

Custom Search

More Threads

• Communications Between Multiple Instances
• Reflection-Methodinfo
• Drawing text at an angle?
• How to create Quick info and/or parameter info for my own code
• ComboBox DropDown
• how to write an event on variable value change?
• Need Help with Event Processing
• Chart in a Window
• String$ versus String
• VB variables