tags:

views:

482

answers:

3

I have a csv file from which I have to populate different tables in database I am using Microsoft.Jet.OleDb.4.0 to convert csv file to data table from where I proceed forward

the problem is when I do this a value such as "0261" is stored as 261, the leading zero is dropped, is there a way to prevent it???

Thanks in advance...

A: 

If you store the value as a number, then there is no way to prevent it. All you can do is format the number in a report with leading zeros.

Another option is to store the number as four letter string (char(4)).

Aaron Digulla
the data is not confined to a four letter string it may be as large as 10 digit
Utkarsh
In that case, there is nothing you can do. Numbers in a database are always stored without leading zeros.
Aaron Digulla
Or you can use `varchar(256)` :)
Aaron Digulla
I found a solution just now I enclosed the number with double quotes after that it preserved 0s as it is now a string but the problem is it should be done where csv is genereated on which I dont have any control :(
Utkarsh
A: 

Not possible to preserve zeros as numbers using oledb... wrote my own class to avoid using oledb and preserving zeros

http://bit.ly/8hTSb5

Utkarsh
If his answer helped, wouldn't it be better to accept his answer?
Svish
I used other ways to find my way through...
Utkarsh
+1  A: 

Try this site. http://kbcsv.codeplex.com/.

This will be easier to use and will give you your datatable.

Middletone