使用VFPOLEDB驱动程序读取DBF
我正在使用 VFPOLEDB 驱动程序读取 DBF 文件,并且不断收到此错误,但我不知道为什么以及如何解决该问题:
提供程序无法确定十进制值。例如,该行刚刚创建,Decimal 列的默认值不可用,并且使用者尚未设置新的 Decimal 值。
这是代码。我调用此例程来返回 DBF 文件的数据集并在 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;
}
}
I am using VFPOLEDB driver to read DBF files and I keep getting this error and I am not sure why and how to fix the problem:
The provider could not determine the Decimal value. For example, the row was just created, the default 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 routine to return a DataSet of the DBF file and display the data in a 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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在这里找到了解决方案:
读取某些数值时出错VFPOLEDB驱动
I found the solution here:
Error reading certain numeric values with VFPOLEDB driver
我最终通过获取表模式,然后在 select 语句中将所有非字符字段转换为 varchar 解决了这个问题。足以预览表格的内容。
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.
这是一个已知问题。
特别是,如果您需要选择所有列,则更加方便:
一种可行的解决方案是使用另一个提供程序,例如 Microsoft.Jet.OLEDB.4.0。
示例连接字符串可以在这里找到: http://docs.30c.org/conn/dbf -foxpro.html
It is a known issue.
Especially, if You need to select all columns, it is much more comfortable:
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
如果您从 gridview 添加一行,它不一定使用默认值,而是使用 NULL,因此您可能需要预先设置默认值,或将架构设置为不允许空值。
您可以在查询完成后自动遍历列,并根据列数据类型强制使用默认值,例如
这些只是 3 种默认类型,但可能还有其他类型,如布尔值、小数、浮点数等,只需添加到 if/否则并输入任何“默认”值。它可能有助于在添加新行时注入“NULL”值。
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
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.