Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver
Go Back  Xtreme Visual Basic Talk > > > Reading TAB delimited file using MS Text Driver


Reply
 
Thread Tools Display Modes
  #1  
Old 06-14-2011, 10:30 AM
descartes75 descartes75 is offline
Centurion
 
Join Date: Jul 2003
Posts: 186
Default Reading TAB delimited file using MS Text Driver


This problem is driving me crazy. I am trying to import a TAB (NOt comma) delimited text file into a DataGridView. The following code works fine if I have a comma separated file. All I have to do is change the FMT to "Delimited".

It just does not work with FMT=TabDelimited. All columns are read into single datatable column. The text file is ANSI text and I have double checked to make sure Tabs are tabs and not spaces, even exported a sample Tab Delimited file from Excel. Can this even be done using Text Driver?



Public Function ReadCSV(ByVal TextFile As String) As DataTable


Dim csvFileFolder As String
csvFileFolder = IO.Path.GetDirectoryName(TextFile)
Dim csvFileName As String
csvFileName = IO.Path.GetFileName(TextFile)


'Note that the folder is specified in the connection string,
'not the file. That's specified in the SELECT query, later.
Try
Dim connString As String = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" _
& csvFileFolder & ";Extended Properties=text;HDR=YES;FMT=TabDelimited"

Dim conn As New Odbc.OdbcConnection(connString)

'Open a data adapter, specifying the file name to load
Dim da As New Odbc.OdbcDataAdapter("SELECT * FROM [" & csvFileName & "]", conn)
'Then fill a data table, which can be bound to a grid
Dim dt As New DataTable
da.Fill(dt)

Return dt

Catch ex As Exception
MsgBox(ex.Message)
end try
End Function
Reply With Quote
  #2  
Old 06-14-2011, 10:51 AM
AtmaWeapon's Avatar
AtmaWeaponReading TAB delimited file using MS Text Driver AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

You can't use it that way.

See this page for information about the connection string. The connection string just says "use this driver". You have to make a schema.ini file in the same directory as the text files you are loading. Don't trust a third-party site? Have a look at an MS KB..

The fun part? It looks like you need to add an INI section for *every file you want to load*. That's kind of hard to do in advance. I recommend using the TextFieldParser class instead. There'll be a little bit more footwork to get the data into the grid view. That's the price paid for pretending delimited text files are a database format.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 06-14-2011, 10:57 AM
descartes75 descartes75 is offline
Centurion
 
Join Date: Jul 2003
Posts: 186
Default

Thanks . I was beginning to suspect that. I would have used CSV but cells could contain commas and if a user edits the text file, chances are he may miss the double quotes.
I will use the parser.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver
 
Reading TAB delimited file using MS Text Driver
Reading TAB delimited file using MS Text Driver
 
-->