Concurrency violation the updatecommand affected 0 records

G

Guest

Hello,
I have a problem whereby I have a datagrid that is bound to a
dataTable.
However occassionally when I edit the datagrid I get the following message.

Concurrency Violation the update Command affected 0 records.

The message appears to be completely random and If I go back out and into
the form again
it may then work properly.
I looked at the value of the updatecommand in the sqldataadapter and it
always says nothing.

Why does this message occur, is it to do with writing null values back to
the database.
The database gets updated when a cell is clicked on the grid using the
CurrentCellchanged event.
I have attached the relevant code for your assistance.

Thanx in advance.

Geri


MyDataGrid.DataSource = MyDataTable

Private Sub MyDataGrid_CurrentCellChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles MyDataGrid.CurrentCellChanged
Dim IntNumRows As Integer = MyDataTable.Rows.Count
IntRowNum = MyDataGrid.CurrentCell.RowNumber

If IntRowNum < IntNumRows Then
Call UpdateTempJobs()
End If

End Sub

Private Sub UpdateTempJobs()
DirectCast(BindingContext(MyDataTable),
CurrencyManager).EndCurrentEdit()
Call DataAccess.UpdateDataSet(MyDataGrid, MySqlDataAdapter,
MyDataTAble)

End Sub

Public Sub UpdateDataSet(ByRef MyDataset As DataSet, ByVal Mysqldataadapter
As SqlDataAdapter, ByVal strTable As String)
Dim objCommandBuilder As New SqlCommandBuilder(Mysqldataadapter)

Mysqldataadapter.Update(MyDataset, strTable)

End Sub
 
C

Cor Ligthert

Geraldine,

It has probably to do with the updated records in your dataset.
They are not updated when you use by instance autoincrement keys

Than you have after every update to clear the dataset and fill it completly
new especially in a multiuser environment.

I hope this helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top