Click here to Skip to main content
13,145,068 members (54,408 online)
Rate this:
Please Sign up or sign in to vote.
I have an Excel 2003 file that has a table on a spreadsheet

I can successfully fill a datatable and a datagridview using a dataadapter

When I come to use the update command however I always get a concurrency error, I don't believe it's a concurrency error but that seems to be the default error messages for zero records updated

The connection string is
Provider=Microsoft.ACE.OLEDB.12.0;Data Source= F:\My Folder\My Sheet.xls; <br />
Extended Properties="Excel 8.0;HDR=YES";

The update statement for testing is
Update [My_Sheet$] Set [Part Code]='__foo' where ([Part Code] like '*OQ2*')

The update code is
Public Sub Update(ByVal value As PartsList.PartsListDataTableDataTable)
    Catch ex As DBConcurrencyException
        If Me.m_oDataAdapter.UpdateCommand.Connection.State = ConnectionState.Open Then Me.m_oDataAdapter.UpdateCommand.Connection.Close()
    End Try
End Sub

Error detail is:

System.Data.DBConcurrencyException was caught
Message: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

The stack trace is:

at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at DO_Tools.PartsListDataAdapter.Update(PartsListDataTableDataTable value) in C:\Users\Me\documents\visual studio 2010\Projects\DO_Tools\DO_Tools\_DataAdapters\PartsListDataAdapter.vb:line 168

I've changed the syntax but the error persisted

Can anyone offer a suggestion why this is not working?
Posted 15-Jan-13 9:56am
Updated 15-Jan-13 11:14am
richcb 15-Jan-13 16:18pm
You need to change your syntax for the where clause regarding the like condition. SQL uses % instead of *. I don't know if that is your entire problem, but it might be some of it. It would also be helpful to post your error so we can check it out.
Fawxes 15-Jan-13 17:15pm
richcb - 32 mins ago
Comment from richcb copied over:
Next time use the "Improve Question" widget to add code or anything else to your thread. I found this thread that has various solutions. You may look through them and see if any of them help you.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I've found the solution

I had added parameters for all the columns to the update command but I wasn't using all of them during testing, only Specification and Part Code and even these weren't used in the update command during testing.

By changing the update command only adding the parameters that were referenced in the update command then the update action works fine.

Amended Update Command:
Update [My_Sheet$] Set [Specification]=? where ([Part Code] = ?)

Amended Code:
Me.m_oDataAdapter.UpdateCommand = New OleDb.OleDbCommand(sUpdateSQL, Me.m_oConn)
              Me.m_oDataAdapter.UpdateCommand.Parameters.Add(&amp;quot;@Specification&amp;quot;, OleDb.OleDbType.Char, 255, &amp;quot;Specification&amp;quot;)
       Me.m_oDataAdapter.UpdateCommand.Parameters.Add(&amp;quot;@OldPartCode&amp;quot;, OleDb.OleDbType.Char, 255, &amp;quot;PartCode&amp;quot;).SourceVersion = DataRowVersion.Original
richcb 15-Jan-13 17:23pm
Good job.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 15 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100