更新dbf文件时,operator / operand类型不匹配

时间:2013-03-25 02:25:42

标签: vb.net oledb foxpro dbf visual-foxpro

我有一个程序需要更新dbf文件中的数据。但它会出现错误'操作符/操作数类型不匹配'。这是示例代码:

    Dim con As OleDbConnection = New OleDbConnection("Provider=vfpoledb;Data Source=C:\folder\paytran.dbf;Collating Sequence=machine;")
    Try


        Dim strSQL As String = "UPDATE paytran.dbf SET workhr = 20  WHERE empno = 102"
        Dim cmd As OleDbCommand = New OleDbCommand(strSQL, con)
        con.Open()
        Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
        Dim myDataSet As DataSet = New DataSet()
        ' Using DataAdapter object fill data from database into DataSet object
        myDA.Fill(myDataSet, "MyTable")
        ' Binding DataSet to DataGridView
        DGV.DataSource = myDataSet.Tables("MyTable").DefaultView
        con.Close()
        con = Nothing
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Error Select Data")

    Finally
        If con IsNot Nothing Then
            con.Close()
        End If
    End Try

请帮帮我..

2 个答案:

答案 0 :(得分:0)

它是你的连接字符串。连接字符串应该只需指向数据文件所在的PATH,然后所有基于SQL的命令将默认能够在该路径中查看任何.DBF表(或者如果存在子路径则转发)。

Data Source=C:\folder

而不是

Data Source=C:\folder\paytran.dbf

所以,现在如果你在“C:\文件夹”中有30个表,你现在可以根据需要从所有表中查询。

答案 1 :(得分:-1)

您需要明确打开和关闭DBF。尝试:

Dim strSQL As String = "Use paytran in 0 shared;UPDATE paytran SET workhr = 20  WHERE empno = 102;use in select('paytran')"