Question

i have a program needs to update data in dbf file. but it keeps appear error 'operator/operand type mismatch'. here is sample code :

    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

please help me..

Was it helpful?

Solution

Its your connection string. The connection string should only have to point to the PATH where the data files are located, then all the SQL based commands will by default be able to see any .DBF tables IN that path (or forward if subpaths exists).

Data Source=C:\folder

instead of

Data Source=C:\folder\paytran.dbf

So, now if you have 30 tables in the "C:\folder", you can now query from ALL of them as needed.

OTHER TIPS

You need to explicitly open and close the DBF. Try:

Dim strSQL As String = "Use paytran in 0 shared;UPDATE paytran SET workhr = 20  WHERE empno = 102;use in select('paytran')"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top