none
DataAdapter.Update(Dataset) 'Concurrency violation: the UpdateCommand affected 0 of the expected 1 records RRS feed

  • Question

  • Hi all

    I'am testing the DBConcurrencyException error to manage this efficiently, but my test project seem to be no working at all.

    My form have tow datagridview with two OdbcDataAdapter, and two DataSet, each of one bind to each datagridview but pointing to the same table, like two differents users using the same applications data.

    But I try to save the second grid I get the DBConcurrencyException and test all the solutions in MSDN but I can't get to work correctly.

    I apreciate any help that you can give me.

    My code

    Public Class Form1
    
    
        Private strCNN As String = ";DSN=TESTDB;UID=user;PWD=xx"
    
        Private daTmp1 As OdbcDataAdapter
        Private cbCab1 As New OdbcCommandBuilder()
        Private dsCab1 As New DataSet
    
        Private daTmp2 As OdbcDataAdapter
        Private cbCab2 As New OdbcCommandBuilder()
        Private dsCab2 As New DataSet
    
        Private strSql As String = " SELECT * FROM Pa_Cargos order by 1 "
    
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            DataLoad()
    
        End Sub
    
        Private Sub DataLoad()
    
            'Codigo para DataGrid 1 Code
            daTmp1 = New OdbcDataAdapter(strSql, strCNN)
            '---
            cbCab1.DataAdapter = daTmp1
            '---
            dsCab1.Clear()
            daTmp1.Fill(dsCab1)
    
            Me.DataGrid1.DataSource = dsCab1.Tables(0)
            Me.DataGrid1.Refresh()
    
    
            'Codigo para DataGrid 2
            daTmp2 = New OdbcDataAdapter(strSql, strCNN)
            '---
            cbCab2.DataAdapter = daTmp2
            '---
            dsCab2.Clear()
            daTmp1.Fill(dsCab2)
    
            Me.DataGrid2.DataSource = dsCab2.Tables(0)
            Me.DataGrid2.Refresh()
    
        End Sub
    
    
        Private Sub cmdSaveGRid1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveGRid1.Click
            On Error GoTo Proc_Err
            daTmp1.Update(dsCab1)
            Exit Sub
    Proc_Err:
            MsgBox(Err.Number & " - " & Err.Description)
        End Sub
    
    
        'Test the Second Grid - Concurrency Error !!!
        Private Sub cmdSaveGRid2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveGRid2.Click
            On Error GoTo Proc_Err
    
            Dim strUpdate As String = String.Empty
    
            daTmp2.UpdateCommand = cbCab2.GetUpdateCommand
    
            strUpdate = "UPDATE [Pa_Cargos] SET [COD_CARGO] = ?, [DESCRIPCION] = ?, [USR] = ?, [FEC_REG] = ?, [STATUS] = ? WHERE (([COD_CARGO] = ?)) "
            daTmp2.UpdateCommand.CommandText = strUpdate
            Debug.Print(daTmp2.UpdateCommand.CommandText)
    
    
            daTmp2.Update(dsCab2)
    
    
            Exit Sub
    Proc_Err:
            daTmp2.UpdateCommand.CommandText = strUpdate
            MsgBox(Err.Number & " - " & Err.Description)
            'TestForErrors(dsCab2)
            Resume Next
        End Sub
    
    
    End Class




    Programador en VB.NET 2008, SQL SERVER 2008, Crystal Report 2008 Si la respuesta es correcta, marcála como correcta. También puedes votar como útil si te sirvió.
    • Edited by Bitnius Sunday, June 14, 2009 2:39 AM .
    Sunday, June 14, 2009 2:13 AM

All replies

  • You are using the same DataAdapter to fill the 2 separate DataSets.

    Instead of code:

    daTmp1.Fill(dsCab2)

    Use Code:

    daTmp2.Fill(dsCab2)

    Monday, June 15, 2009 9:23 PM
    Moderator
  • Hi

    I already fix that mistype and the error still present !

    Greetings
    Programador en VB.NET 2008, SQL SERVER 2008, Crystal Report 2008 Si la respuesta es correcta, marcála como correcta. También puedes votar como útil si te sirvió.
    Tuesday, June 16, 2009 12:15 AM