Search code examples
c#dbfdbase

ColumnSize of numeric is not same original (c#)(dBase)


I want to get a database schema (dBase), so I use "oledb" to get data from a dbase file for using getchemaTable to get the schema of data, but the "ColumnSize" of the numeric data type excludes "19". As the original data, such as "object_id" Type: nummeric column size: 12, but it returns the output to "19".

I want to show the results to the exact same. but.. I don't know what to do next.

public static DataSet getStructureDBF(string dir, string input)
    {
        OleDbConnection objConn = new OleDbConnection(@"Provider=VFPOLEDB.1;Data Source=" +         dir + ";Persist Security Info=False;");
        objConn.Open();
        OleDbCommand objCmd = new OleDbCommand("Select * from " + input, objConn);

        OleDbDataReader objDataReader = objCmd.ExecuteReader();
        DataTable schemaTable = objDataReader.GetSchemaTable();
        DataSet dsnew = new DataSet();
        dsnew.Tables.Add(schemaTable);
        return dsnew;
    }

Solution

  • For all data types, dBASE field definitions store field length and precision. The latter is only relevant for numeric types, and the former is the maximum number width in digits, because that is how dBASE stores numbers: actual strings of digits.

    See dbf file format specification

    Edit

    Note that data types Numeric and Float are stored as strings of digits. Number types in more recent versions of dBASE are stored as binary values.

    Also see DBF reader implementation notes