Hello,
I am relatively new to VB.net and I would like some help. I am getting a concurrency violation when trying to do an update. I have done some research and tried various suggestions but nothing seems to work.
Here's the situation:
I create an SQL connection, add a new row to the dataset and update the database.
After this, I have another section on the form with a checkbox and two text boxes. The text boxes are only enabled if the check box is checked.
The error occurs when checking the check box.
How can I update the database at this point without receiving the error?
I will also be updating the database once the textbox values are entered.
The database is setup as such:
- DefaultID, int, primary key, Identity Specification is YES
- UseLogin, tinyint, null
- UserName, Varchar(80), null
- Password, varchar(80), null
- LastLogin, datetime, null
Any help would be greatly appreciated.
I am relatively new to VB.net and I would like some help. I am getting a concurrency violation when trying to do an update. I have done some research and tried various suggestions but nothing seems to work.
Here's the situation:
I create an SQL connection, add a new row to the dataset and update the database.
Code:
Public Sub Load_DefaultDataset()
'// Gets the default values from the database.
Try
Dim cmdbuilder As SqlClient.SqlCommandBuilder
Dim dsNewRow As DataRow 'New dataset row.
g_daDefaults = New SqlClient.SqlDataAdapter("SELECT * FROM Defaults", pihCONN) 'pihCONN is previously defined.
g_dsDefaults.Clear()
cmdbuilder = New SqlClient.SqlCommandBuilder(g_daDefaults)
g_daDefaults.Fill(g_dsDefaults, "Defaults")
'// Create a new datarow object.
If g_dsDefaults.Tables("Defaults").Rows.Count = 0 Then
dsNewRow = g_dsDefaults.Tables("Defaults").NewRow() '// Create a new datarow.
g_dsDefaults.Tables("Defaults").Rows.Add(dsNewRow) '// Add the new row to the dataset.
End If
g_dsDefaults.Tables("Defaults").Rows(0).Item("LastLogin") = Today.Date
g_daDefaults.Update(g_dsDefaults, "Defaults")
Catch ex As Exception
'// Use my own error handler.
ErrorMessenger(Err.Number, ex.Message, "GlobalMod.Load_DefaultDataset")
End Try
End Sub
After this, I have another section on the form with a checkbox and two text boxes. The text boxes are only enabled if the check box is checked.
The error occurs when checking the check box.
Code:
g_dsDefaults.Tables("Defaults").Rows(0).Item("UseLogin") = chkUseLogin.Checked
g_daDefaults.Update(g_dsDefaults, "Defaults") [COLOR=red]<-- **ERROR**[/color]
g_dsDefaults.AcceptChanges()
How can I update the database at this point without receiving the error?
I will also be updating the database once the textbox values are entered.
The database is setup as such:
- DefaultID, int, primary key, Identity Specification is YES
- UseLogin, tinyint, null
- UserName, Varchar(80), null
- Password, varchar(80), null
- LastLogin, datetime, null
Any help would be greatly appreciated.