Reading DBF with VFPOLEDB driver

与世无争的帅哥 提交于 2019-12-01 17:38:06
John Prado

I found the solution here: Error reading certain numeric values with VFPOLEDB driver

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

I finally solved the problem by getting the table schema and then casting all of non-character fields to varchar in the select statement. Good enough for previewing the contents of the table.

It is a known issue. Especially, if You need to select all columns, it is much more comfortable:

Select * from some_table

One working solution is to use another provider, for example Microsoft.Jet.OLEDB.4.0. Example connection string can be found here: http://docs.30c.org/conn/dbf-foxpro.html

DRapp

If you add a row from your gridview, it doesn't necessarily use a default value, but rather NULLs, so you may need to pre-set your defaults, or set the schema to NOT Allow Nulls.

You could automate through the columns after the query is done and force defaults based on the columns data types, such as

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;
}

these are just 3 default types, but there could be others like boolean, decimal, float, whatever, just add into the if/else and put whatever "default" values. It MAY help where otherwise "NULL" values are getting injected in when adding new rows.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!