RE: DBF file - Concurrency violation

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


Date: Tue, 24 Aug 2004 08:05:03 -0700

Now I've tried to use ODBC but I get a System error:

      Dim con As Odbc.OdbcConnection
      Dim daAdaptor As Odbc.OdbcDataAdapter
      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 Odbc.OdbcConnection("Driver={Microsoft dBASE Driver
(*.dbf)};DriverID=277;Dbq=" & Path.GetDirectoryName(strDBF) & ";")
      daAdaptor = New Odbc.OdbcDataAdapter("Select * FROM " &
Path.GetFileNameWithoutExtension(strDBF) _
        , con)
      daAdaptor.Fill(dsData)
      daAdaptor.UpdateCommand = New Data.ODbc.OdbcCommand(Nothing, con)
      With daAdaptor.UpdateCommand
         .CommandText = "Update " & Path.GetFileNameWithoutExtension(strDBF)
& _
            " SET " & "AMT8" & " = @" & "AMT8" & " Where " & _
            "SSN = @SSN"
         .Parameters.Add(New Data.ODbc.OdbcParameter("@SSN",
Data.Odbc.OdbcType.Char, 11, "SSN"))
         .Parameters.Add(New Data.ODbc.OdbcParameter("@" & "AMT8",
Data.Odbc.OdbcType.Double, Nothing, "AMT8"))
      End With
      dsData.Tables(0).Rows(0).Item("AMT8") = "100"
      daAdaptor.Update(dsData.Tables(0))

Can anyone point out where I've gone wrong?

"Wayne Froese" wrote:

> 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))
>