I have a scenario when concurrency happens.
In this case I want to go ahead and update/overwrite the database values with the new values set by me only. if the concurrency is for column named "GUID".
i am using a data adapter to update the table and this cannot change.
If there is a way to ignore values from that specific column "GUID" in all scenarios while updating the changes that is also fine....
"GUID" is a column related to replication in the database so usually the database changes the values and results in concurrency while saving second time.
i want to directly update the database with my new values if the concurrency has occured in one specific column.
Public Sub Save() Implements IDataBaseModel.Save
Try
If Not mTable Is Nothing Then
mAdapter.Update(mTable)
mTable.AcceptChanges()
End If
Catch dbcx As Data.DBConcurrencyException
MessageBox.Show("Data has changed in the backend since the last retrieve. Close the screen and try saving again.", GetAssemblyName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Catch ex As Exception
MessageBox.Show("Something went wrong! " & Environment.NewLine & ex.Message, GetAssemblyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Function ReadRows() As DataTable
If mTable Is Nothing Then
Dim sw As New Stopwatch
sw.Start()
Dim sql As String = "SELECT * FROM " & mTableName
mAdapter = New SqlClient.SqlDataAdapter(sql, DatabaseManager.GetManager.GetConnection)
Dim builder As New SqlClient.SqlCommandBuilder(mAdapter)
mAdapter.UpdateCommand = builder.GetUpdateCommand
mAdapter.DeleteCommand = builder.GetDeleteCommand
mAdapter.InsertCommand = builder.GetInsertCommand
' Now set the select sql, if specified
If Not mSelectSQL = "" Then
sql = mSelectSQL
End If
If Not mParentIDFilter = 0 Then
If Not ParentIDColumn = "" Then
If sql.ToLower.Contains("where") Then
sql &= " and " & ParentIDColumn & "=" & mParentIDFilter
Else
sql &= " WHERE " & ParentIDColumn & "=" & mParentIDFilter
End If
Else
gLogClient.Exception("No ParentIDColumn defined", Me, "ReadRows()")
End If
End If
mAdapter.SelectCommand = New SqlClient.SqlCommand(sql, DatabaseManager.GetManager.GetConnection)
mTable = New DataTable
mAdapter.Fill(mTable)
'AddHandler mTable.TableNewRow, AddressOf OnTableNewRow
sw.Stop()
gLogClient.Info("Table filled using sql '" & sql & "' in " & sw.ElapsedMilliseconds & " milliseconds", Me, "ReadRows()")
mDataLastRead = Now
End If
Return mTable
End Function
To reproduce the scenario of the replication set up of my system (which automatically changes the GUID column everytime there is a update in the database) all you can do is
1.Load the data from the readrows() and load a dataggrid
2.Now go to your database and mae changes to one of the column with a sql query
3.Now try to come back to your datgaridview and press save which should execute the save() function
4.Now the save will not work becuase a concurrency error happens since you have changed the data in the backend after you fetched data.So the data has changed in the backend.