views:

42

answers:

1

My tab-delimited file is something like this:

ISO ISO3    ISO-Numeric
AD  AND 20

I've been trying the following code with no luck.

        OleDbConnection cn = new  OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=
|DataDirectory|;Extended Properties='text;HDR=Yes;FMT=TabDelimited'");

        OleDbCommand cmd = new OleDbCommand(@"SELECT * FROM countryInfo.txt", cn);
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);

        cn.Open();

        DataTable dt = new DataTable();

        da.Fill(dt);

Here's a screenshot of the Dataset Visualizer. Its obviously not the output i'm after. alt text

Any suggestions? Here's my Schema.ini file. Its in the same directory as the text file.

[countryInfo.txt]
Format=TabDelimited
ColNameHeader=True
CharacterSet=ANSI

Should i just use something like FileHelpers instead?


@Hans Passant Here's a screenshot. alt text

+1  A: 

Well, one obvious candidate is that this white space isn't actually a tab but spaces. Try FMT=Delimited( ). Use a hex viewer to see what's really there. Backgrounder is here.

And this thread shows why using a buggy chunk of code like Jet that hasn't been supported for the past 9 years is such as mistake. With the answer, leave the first line in schema.ini blank.

Hans Passant
FMT=Delimited( ) didn't work. When i open the file in a hex editor i see '.' between fields. What does that really mean?
smkngspcmn
You are supposed to see hex numbers, not dots. Post a screen shot.
Hans Passant
No clue what "bh" might mean, that was the point of asking for a screen shot. 09 is indeed the ascii code for a tab.
Hans Passant
Yes its 09. Screenshot above.
smkngspcmn
It is tab delimited. The file is encoded in utf-8, probably too advanced for JET. The 1st 3 bytes in the file is the BOM, that's what produces the # in the output. You could open the file in notepad and save it back with Encoding set to ANSI. See if that makes a difference. I don't really get the 'all jumbled together' remark btw.
Hans Passant
Saved it back in ANSI but even that didn't make a difference. What i was trying to say was that delimited fields weren't properly separated in my output. I'll re-edit the question with my full code and a screenshot of the output. I'm sure this is all to do with something stupid on my part, this is the first time i'm using OleDb to read this sort of a file.
smkngspcmn
No idea. Check this thread: http://social.microsoft.com/Forums/en-US/Offtopic/thread/9f7d2b67-cea5-4840-96ef-2e12011752d7
Hans Passant