如何从 .DBF 数据库中读取星号 (***) 字段? [英] How do I read asterisk (***) fields from .DBF data base?

查看:23
本文介绍了如何从 .DBF 数据库中读取星号 (***) 字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 VB.NET 读取 .DBF 数据库...代码一直在工作,直到我到达其中一个表上的一列,该列应该是 Decimal,但它被填充了星号.

I'm trying to read a .DBF data base using VB.NET... the code is working until I reach a column on one of the tables that is supposed to be Decimal but it is instead filled with asterisks.

我使用的连接字符串和阅读器如下所示:

The connection string and reader I'm using go like this:

Using SDBconnection As New OleDbConnection("User ID=;" & _
                                                    "DSN=;" & _
                                                    "Cache Authentication=False;" & _
                                                    "Data Source=""" & TextBox_DBLoc.Text & """;" & _
                                                    "Provider=""VFPOLEDB"";" & _
                                                    "Collating Sequence=MACHINE;" & _
                                                    "Mask Password=False;" & _
                                                    "persist security info=False;" & _
                                                    "Mode=Share Deny None;" & _
                                                    "Extended Properties=;" & _
                                                    "Encrypt Password=False")

Dim oleReader As OleDbDataReader = New OleDbCommand("Select * from " & table, SDBconnection).ExecuteReader()

是否有某种方法可以评估数据类型何时不对应,然后是强制转换或类似的东西?

Is there some way to evaluate when the data type does not correspond and then to a cast or something like that?

该表在其他DBF阅读器软件中可以读取,读取时没有显示错误.我该怎么做?

The table is readable in other DBF reader software and no error is showed when read. How can I do the same?

当我的代码到达带有星号的列时抛出的错误消息是这样的:

The error message thrown by my code when it reaches the column with asterisks is this:

提供者无法确定 Decimal 值.例如,该行刚刚创建,Decimal 列的默认值不可用,并且使用者尚未设置新的 Decimal 值.

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.

推荐答案

Visual Foxpro 存在一个问题,它显然允许用户在数字字段中输入溢出的值,而这在 Visual Foxpro 中似乎不会引起问题.但是,当使用 Visual Foxpro 以外的任何东西访问数据时,它确实会导致问题,因为它违反了该字段的设置.VFPOLEDB 将这些值作为星号返回.作为解决方法,您可以尝试以下查询:

There is a problem with Visual Foxpro that apparently allows the user to enter a overflowed value in numeric fields which doesn't seem to cause an issue in Visual Foxpro. However, it does cause problems when accessing the data using anything other than Visual Foxpro because it violates the settings for this field. VFPOLEDB returns these values as asterisks. As a workaround, you could try the following query:

SELECT VAL(STR(SaleAmt)) as SaleAmt FROM MyTable

这会将十进制列 (SaleAmt) 转换为字符串,然后再转换回数值.

This converts the decimal column (SaleAmt) to a string and then back to a numeric value.

您也可以检查您的数据是否存在溢出值并修改 dbf 表结构来解决此问题.

You also can check your data for overflowed values and modify the dbf table structure to solve this problem.

这个链接解释了这个问题

这篇关于如何从 .DBF 数据库中读取星号 (***) 字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆