views:

272

answers:

2

Using .NET

I have a text file with comma separated data. One of the columns consists of text like the following : 1997/020269/07

Now when I do a select with an OdbcCommand the string is seen as a float and it returns the 'answer' instead of the actual text!

How can I get the actual text? Am I going to be forced to parsing the file manually?

Hope someone can help...please?! :)

Edit: Some code maybe? :)

string strConnString =
            @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + _FilePath +
            @"; Extensions=asc,csv,tab,txt;Persist Security Info=False";

var conn = new System.Data.Odbc.OdbcConnection(strConnString);

var cmd = new System.Data.Odbc.OdbcCommand("select MyColumn from TextFile.txt", conn);
var reader = cmd.ExecuteReader();


while (reader.Read())
{ Console.WriteLine(reader["MyColumn"]); }

This returns 0.014074977 instead of 1997/020269/07

+2  A: 

Have you tried using a schema.ini file -- these can be used to explicitly define the format of the text file, including data types.

Your schema.ini file might end up looking a little like:

[sourcefilename.txt]
ColNameHeader=true
Format=CSVDelimited
Col1=MyColumn Text Width 14
Col2=...
Rowland Shaw
Nice link. I hope you'll elaborate just a bit?
John Saunders
...like that...
Rowland Shaw
A: 

Try using schema.ini

[yourfile.txt]
ColNameHeader=false
MaxScanRows=0
Format=FixedLength
Col1=MyColumn Text Width 20

Bye.

RRUZ