VB.NET – 带有数字十进制列的Visual Foxpro OLE DB问题

前端之家收集整理的这篇文章主要介绍了VB.NET – 带有数字十进制列的Visual Foxpro OLE DB问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
简而言之:
我正在使用VB.NET 2008使用vfpoledb.1驱动程序连接到Visual Foxpro 6数据库.当我尝试使用包含其中一个数字列的数据集表填充OleDbDataAdapter时,我收到以下错误消息:

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.

我想从VB.NET 2008中检索此列并将其保存为数字格式.

长版:

我正在使用VB.NET连接到Visual Foxpro 6数据库.表中的几个列适用于最多8位数的数字数据类型.我不确定Visual Foxpro数据类型是如何工作的,但似乎此字段允许某人输入以下任何示例值:

99999999  
99999.99  
    9.99  
    9.00
{nothing}

从Visual Foxpro:我可以访问名为Foxwin的小程序,它允许我在本机VFP环境中浏览VFP表.这就是我用来访问数据以获取我上面发布的内容的示例.从这里我可以看到一些行在这个字段中根本不包含任何值,尽管它们在没有数据时似乎被填充空格.我试图运行更新查询以使用有效数据填充每一行但我的更新查询完成而不更新任何行.我已经尝试过ISNULL(bal_qty)和bal_qty IS NULL,但两个都没有.

从MS Access 2007:使用我在VB.NET中使用的相同驱动程序,我可以加载ADO记录集并将其绑定到表单没有问题.小数值似乎被剥离,可能是因为它们都是“.00”.我更喜欢在VB.NET中构建这个小程序,所以我只使用MS Access进行测试.

从VB.NET:如果我将bal_qty转换为String,我的sql语句可以工作,但这会导致排序问题.我已经尝试了VAL(STR(bal_qty))并且它失败并且我在上面发布了相同的错误消息.这是我正在使用的代码

Imports System.Data.OleDb

Public Class Form1
    Dim sConString As String = "Provider=vfpoledb.1;Data Source=C:\MyDatabase.dbc;Mode=3;"
    Dim con As OleDbConnection = New OleDbConnection(sConString)

    Private Function FetchData()

        con.Open()
        Dim ds As DataSet = New DataSet()
        Dim ssql As String
        'This sql statement works but the data doesn't sort properly.
        'ssql = "SELECT item_cd,item_desc,STR(bal_qty) FROM invent;"

        ssql = "SELECT item_cd,bal_qty FROM invent;"

        Dim cmd As OleDbCommand = New OleDbCommand(ssql,con)
        Dim daInv As OleDbDataAdapter = New OleDbDataAdapter(cmd)
        Dim iRecCount As Integer
        iRecCount = daInv.Fill(ds,"invent") 'The error occurs here.
        Me.DataGridView1.DataSource = ds.Tables("invent").DefaultView
    End Function

    Private Sub btnFetchData_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles btnFetchData.Click
        Call FetchData()
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object,ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        con.Close()
        con = Nothing
    End Sub
End Class

解决方法

我们有一个.NET应用程序读取foxpro dbf的问题.我们的解决方案是在select语句中使用以下内容

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

这会将十进制列(SaleAmt)转换为字符串,然后再返回到数值.此外,如果需要整数,则可以在SELECT语句中使用INT(SaleAmt).

猜你在找的VB相关文章