I am reading field type of DBF file. I am also creating DBF file. I am using oledb reader to get filedtype. Reader always return decimal type weather i set Numeric,Float or double. Why is it so? Why reader is not returning same type as stored in DBF?
Different providers may map the physical field types of a DBF to different OLEDB field types.
Another issue is the SQL result type guessomatic that kicks in if you select expressions (select amt * 0.01 from foo
) instead of naked fields and do not cast the result to some type explicitly (select cast(amt * 0.01 as currency) from foo
). Again, different providers/engines may give different results in such a situation; some - like the VFP9 provider - allow explicit casts, some do not.
You may get better results if you switch to a different provider. For example, the Visual FoxPro 9.0 OLEDB provider - which is freely available for download - maps the Fox DBF field types 'I' (integer), 'B' (double), 'Y' (currency) and 'N' (numeric) faithfully to the corresponding OLEDB/ADO field types adInteger
, adDouble
, adCurrency
and adNumeric
. On the other hand, the Fox provider understands only the Fox field types and legacy DBF types corresponding to Clipper and dBASE 3 or thereabouts. It cannot read tables produced by newer dBASE versions.
Several of the freely available OLEDB providers understand some DBF dialect or other; which one is most suitable would depend on the type of your DBF files.
The DBF file structure is fairly simple; depending on your application it might make sense to pull the meta data directly from the field definitions in the DBF header.