Hi Guys,
I am using VB.net 2010 and SQL Server 2008 R2 express. I've been reading all about concurrent violation on the web as its an occasional problem on my system too.
I think I understand why its happening i.e. data changed in datagridview and dataset doesn't match underlying data in sql server table.
But what I cannot find online is a good example I can follow that will work and help me avoid this problem, or even if it not avoidalbe the best way to handle it for the user!
Here is my shortened code that populates my dataset.
and then the code to save any changes the user makes.
All help appreciated.
I am using VB.net 2010 and SQL Server 2008 R2 express. I've been reading all about concurrent violation on the web as its an occasional problem on my system too.
I think I understand why its happening i.e. data changed in datagridview and dataset doesn't match underlying data in sql server table.
But what I cannot find online is a good example I can follow that will work and help me avoid this problem, or even if it not avoidalbe the best way to handle it for the user!
Here is my shortened code that populates my dataset.
VB.NET:
Private conn As New SqlClient.SqlConnection(connStr)
Private cmd As SqlCommand
Private ds As New DataSet
Private da3 As SqlDataAdapter
Private bs3 As New BindingSource
'
'
'
cmd = New SqlCommand("SELECT * FROM TblService WHERE ClientID=@ClientID", conn)
cmd.Parameters.AddWithValue("@ClientID", ClientID)
da3 = New SqlDataAdapter(cmd)
da3.Fill(ds, "ClientServices")
bs3.DataSource = ds.Tables("ClientServices")
Me.BindingNavigator3.BindingSource = bs3
Me.DataGridView3.DataSource = Me.BindingNavigator3.BindingSource
and then the code to save any changes the user makes.
VB.NET:
Private Sub SaveServiceChanges_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
'Code to Save Changes to Client Service in DatagridView 3!
Try
Dim objCommandBuilder As New SqlCommandBuilder(da3)
Me.Validate()
Me.bs3.EndEdit()
da3.Update(ds, "ClientServices")
ShowCloseDialog("Client Services records successfully updated")
Catch ex As Exception
MessageBox.Show(ex.Message, "HCS - Error!")
End Try
End Sub
All help appreciated.
Last edited: