问题
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?
The table is readable in other DBF reader software and no error is showed when read. How can I do the same?
EDIT: The error message thrown by my code when it reaches the column with asterisks is this:
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.
回答1:
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
This converts the decimal column (SaleAmt) to a string and then back to a numeric value.
You also can check your data for overflowed values and modify the dbf table structure to solve this problem.
This link explains this problem
来源:https://stackoverflow.com/questions/29189786/how-do-i-read-asterisk-fields-from-dbf-data-base