DBF file - Concurrency violation

From: Wayne Froese (WayneFroese_at_discussions.microsoft.com)
Date: 08/24/04


Date: Tue, 24 Aug 2004 07:39:03 -0700

I've had a devil of a time trying to get past an ADO.NET problem. I have to
deal with DBF files and update them. I've built my own UpdateCommand for my
Data Adaptor but it doesn't seem to work. I always get a "Concurrency
violation: the UpdateCommand affected 0 records."

I couldn't get the Update command not to bomb so I made it as simple as
possible - the data is on my local machine and I am running as administrator
so I don't think there are rights issues on the database. It has no problem
reading the data, it is just the update command that gives it a problem. I am
certain that no one else has accessed the data either.

I've pruned this code down to this basic issue and put it in a button click
- if you could make this work, I'd be happy:

      Dim con As OleDb.OleDbConnection
      Dim daAdaptor As OleDb.OleDbDataAdapter
      Dim dsData As New DataSet
      Dim strDBF As String = "C:\_clients\Canada\ROLLAND INC\NON
SYNDIQUES\2002-01-01\Data dec2001\cdc.dbf"
      con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & _
         Path.GetDirectoryName(strDBF) & ";Extended Properties=dBASE IV;User
ID=Admin;Password=")
      daAdaptor = New OleDb.OleDbDataAdapter("Select * FROM " &
Path.GetFileNameWithoutExtension(strDBF) _
        , con)
      daAdaptor.Fill(dsData)
      daAdaptor.UpdateCommand = New Data.OleDb.OleDbCommand(Nothing, con)
      With daAdaptor.UpdateCommand
         .CommandText = "Update " & Path.GetFileNameWithoutExtension(strDBF)
& _
            " SET " & "AMT8" & " = @" & "AMT8" & " Where " & _
            "SSN = @SSN"
         .Parameters.Add(New Data.OleDb.OleDbParameter("@SSN",
Data.OleDb.OleDbType.Char, 11, "SSN"))
         .Parameters.Add(New Data.OleDb.OleDbParameter("@" & "AMT8",
Data.OleDb.OleDbType.Double, Nothing, "AMT8"))
      End With
      dsData.Tables(0).Rows(0).Item("AMT8") = "100"
      daAdaptor.Update(dsData.Tables(0))