I have a small problem with my program. When I launch the program I have a few parameters that I run to load datasets, and fill listboxes, etc.
After that, I have an add button that when pressed, adds a new row to the dataset, and then immediately after adds the record to the database, and the record successfully shows up in the lstClients list box.
After that, when I double click on the new added Entry in the listbox (that is now present in the database aswell) and I try to update it, lets say Edit the name or something, and press the save button
I get the following error: "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records."
I dont know where the problem is, the record is now in the database, and since the listbox (which shows the new entry) is bound to the datatable which is bound to the dataset, it should also be there, why is it doing this? Any help is much appreciated as I am lost.
acidflash
VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Activate()
ClientsConnection.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source =" & Application.StartupPath & "\SS Solutions.mdb"
'ClientsConnection.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source =\\IP.OF.COMPUTER.WITH.DATABASE\FOLDER WITH DATABASE\DATABASENAME.mdb" & Application.StartupPath & "\SS Solutions.mdb"
ClientsConnection.Open()
ClientsString = "SELECT * FROM Clients"
ClientsDA = New OleDb.OleDbDataAdapter(ClientsString, ClientsConnection)
ClientsDA.Fill(ClientsDS, "ClientsMain")
ClientsInc = 0
Dim Caption As New ToolTip()
' Set up the delays for the ToolTip.
Caption.AutoPopDelay = 5000
Caption.InitialDelay = 100
Caption.ReshowDelay = 500
' Force the ToolTip text to be displayed whether or not the form is active.
Caption.ShowAlways = True
' Set up the ToolTip text for the Button and Checkbox.
Caption.SetToolTip(Me.bAddClient, "Add client")
Caption.SetToolTip(Me.bRemoveClient, "Remove client")
Caption.SetToolTip(Me.bSearch, "Search")
Caption.SetToolTip(Me.bReport, "Report")
Caption.SetToolTip(Me.bEditUser, "Edit passwords")
DateOfCall.Text = System.DateTime.Today
dt = ClientsDS.Tables("ClientsMain")
lstClients.DataSource = dt
CalculateAccessPoints()
CalculateInstalled()
CalculatePending()
lblNumOfUsers.Text = dt.Rows.Count
lblTotalInstalled.Text = TotalInstalledUsers
lblTotalPending.Text = TotalPendingUsers
lblNumOfAp.Text = TotalAccessPoints
lstClients.DisplayMember = "FirstName"
lstClients.DataBindings.Add("Name", ClientsConnection, "FirstName")
End Sub
After that, I have an add button that when pressed, adds a new row to the dataset, and then immediately after adds the record to the database, and the record successfully shows up in the lstClients list box.
VB.NET:
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bAddClient.Click
Dim ClientsADDCB As New OleDb.OleDbCommandBuilder(ClientsDA)
Dim ClientsNewRow As DataRow
ClientsNewRow = ClientsDS.Tables("ClientsMain").NewRow()
ClientsNewRow.Item("FirstName") = FirstName.Text
ClientsNewRow.Item("LastName") = LastName.Text
ClientsNewRow.Item("Address") = Address.Text
ClientsNewRow.Item("PhoneNumber") = PhoneNumber.Text
ClientsNewRow.Item("Email") = Email.Text
ClientsNewRow.Item("InternetUsername") = UserName.Text
ClientsNewRow.Item("InternetPassword") = Password.Text
ClientsNewRow.Item("InternetService") = Service.Text
ClientsNewRow.Item("MonthlyPayment") = MonthlyPayment.Text
ClientsNewRow.Item("ClientNum") = ClientNum.Text
ClientsNewRow.Item("DateOfCall") = DateOfCall.Text
ClientsNewRow.Item("AccessPoint") = AccessPoint.Text
ClientsNewRow.Item("CardType") = CardType.Text
ClientsNewRow.Item("Adapter") = Adapter.Text
ClientsNewRow.Item("AntennaType") = AntennaType.Text
ClientsNewRow.Item("AntennaSize") = AntennaSize.Text
ClientsNewRow.Item("DateToBeInstalled") = ToBeInstalled.Text
ClientsNewRow.Item("DateOfInstallation") = InstalledOn.Text
ClientsNewRow.Item("Installed") = Installed.Text
ClientsDS.Tables("ClientsMain").Rows.Add(ClientsNewRow)
ClientsDA.Update(ClientsDS, "ClientsMain")
MsgBox("Client Successfully Added")
FirstName.Clear()
LastName.Clear()
Address.Clear()
PhoneNumber.Clear()
Email.Clear()
UserName.Clear()
Password.Clear()
Service.Clear()
MonthlyPayment.Clear()
ClientNum.Clear()
AccessPoint.Clear()
CardType.Clear()
Adapter.Clear()
AntennaType.Clear()
AntennaSize.Clear()
ToBeInstalled.Clear()
InstalledOn.Clear()
Installed.Clear()
Me.Refresh()
End Sub
After that, when I double click on the new added Entry in the listbox (that is now present in the database aswell) and I try to update it, lets say Edit the name or something, and press the save button
VB.NET:
Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
Dim RecordUpdate As New OleDb.OleDbCommandBuilder(ClientsDA)
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("FirstName") = FirstName.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("LastName") = LastName.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("Address") = Address.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("PhoneNumber") = PhoneNumber.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("Email") = Email.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("InternetUsername") = UserName.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("InternetPassword") = Password.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("InternetService") = Service.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("MonthlyPayment") = MonthlyPayment.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("DateOfCall") = DateOfCall.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("AccessPoint") = AccessPoint.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("CardType") = CardType.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("Adapter") = Adapter.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("AntennaType") = AntennaType.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("AntennaSize") = AntennaSize.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("ClientNum") = ClientNum.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("DateToBeInstalled") = ToBeInstalled.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("DateOfInstallation") = InstalledOn.Text
ClientsDS.Tables("ClientsMain").Rows(lstClients.SelectedIndex).Item("Installed") = Installed.Text
ClientsDA.Update(ClientsDS, "ClientsMain")
MessageBox.Show("Saved")
Me.Refresh()
End Sub
I get the following error: "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records."
I dont know where the problem is, the record is now in the database, and since the listbox (which shows the new entry) is bound to the datatable which is bound to the dataset, it should also be there, why is it doing this? Any help is much appreciated as I am lost.
acidflash