Reading DBF Using the VFPOLEDB Driver

I use the VFPOLEDB driver to read DBF files, and I keep getting this error, and I'm not sure why and how to solve the problem:

The provider cannot determine the decimal value. For example, a row was just created, the default value for the Decimal column was not available, and the consumer had not yet set a new Decimal value.

Here is the code I call this procedure to return the DataSet of the DBF file and display the data in the DataGridView.

public DataSet GetDBFData(FileInfo fi, string tbl)
{
    using (OleDbConnection conn = new OleDbConnection(
    @"Provider=VFPOLEDB.1;Data Source=" + fi.DirectoryName + ";"))
    {
        conn.Open();
        string command = "SELECT * FROM " + tbl;
        OleDbDataAdapter da = new OleDbDataAdapter(command, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;
    }
}
+5
source share
4 answers

, , , , varchar select. .

0

: VFPOLEDB

SELECT CAST(FieldName As NUMERIC(11, 3)) From TableName
+7

, , NULL, NOT Allow Null.

,

foreach (DataColumn oDC in YourDataSet.Tables[0].Columns)
{
   if (oDC.DataType.ToString().Contains("String"))
    oDC.DefaultValue = "";
   else if (oDC.DataType.ToString().Contains("Int32"))
    oDC.DefaultValue = 0;
   else if (oDC.DataType.ToString().Contains("DateTime"))
    oDC.DefaultValue = DateTime.MinValue;
}

3 , , , , , , if/else " ". , "NULL" .

0

. , , :

Select * from some_table

- , Microsoft.Jet.OLEDB.4.0. : http://docs.30c.org/conn/dbf-foxpro.html

0

Source: https://habr.com/ru/post/1733108/


All Articles