tags:

views:

67

answers:

3

Hi, How to read the empty values from the "dbf" file in C#. Currently while reading the dbf files, the empty values in the file are automatically getting converted to default values. Like empty decimal field is converted to "0.000". Can someone please help in way to read the empty fields as they are and not as default values.

+1  A: 

Can you declare your variables (at least the value types) as nullable types:

decimal? myDecimal = null;

Then if there's no value in the field it should be left as null and not set to a default value.

The syntax T? is shorthand for Nullable, where T is a value type. The two forms are interchangeable.

ChrisF
+1  A: 

decimal is a so-called value type and it cannot be null, which is probably why you are getting those default values. However, most databases have a notion of empty values (DbNull), so it would most likely just be a question of reading the value correctly. If you post some code we should be able to help you.

klausbyskov
OleDbConnection objConn = new OleDbConnection(@"Provider=VFPOLEDB.1;Data Source=" + source + ";Persist Security Info=False;mode=Share Exclusive");objConn.Open();OleDbCommand objCmd = new OleDbCommand("Select * from " + dbfFile, objConn);dt.Load(objCmd.ExecuteReader());Here we are trying to load the data from dbf file to data table.In data table the final values contain default values even when the corresponding in the dbf file is of empty values.
Thiyaneshwaran S
+1  A: 

The .dbf file format dates back to the stone age of computing. It never had a notion of an "empty" column value, unassigned fields would get a default value. Support for nullable columns didn't come around until FoxPro. I reckon what you ask for isn't possible.

Hans Passant