When I create a new record and try deleting it right after, I get an "Concurrency violation: the DeleteCommand affected 0 of the expected 1 records." I've been messing around with it for some time now and cannot figure out why. If I add a new record, close my program, re-open and try and delete it, it works fine.
To load my data into my listview:
Save my new data:
Remove current item selected in the listview:
VB.NET:
Dim ds As New DataSet
Dim daTodo As New OleDbDataAdapter
To load my data into my listview:
VB.NET:
Private Sub LoadData()
Dim dt As DataTable = ds.Tables("Todo")
Dim datDate As Date
Dim intIndex As Integer
Dim intLastRow As Integer
Dim intAdded As Integer
Dim datBoldDate As Date
blnLoaded = False
mcDate.RemoveAllBoldedDates()
datDate = lblDate.Text
intLastRow = dt.Rows.Count
intIndex = 0
intAdded = -1
lstTasks.Items.Clear()
Do While intIndex < intLastRow
If dt.Rows(intIndex).Item("dateof") = datDate Then
If dt.Rows(intIndex).Item("checked") = True Then
If chkHideComplete.Checked = True Then
Else
intAdded = intAdded + 1
lstTasks.Items.Add(dt.Rows(intIndex).Item("checked"))
lstTasks.Items(intAdded).SubItems.Add(dt.Rows(intIndex).Item("task"))
lstTasks.Items(intAdded).SubItems.Add(dt.Rows(intIndex).Item("priority"))
lstTasks.Items(intAdded).Checked = True
End If
Else
intAdded = intAdded + 1
lstTasks.Items.Add(dt.Rows(intIndex).Item("checked"))
lstTasks.Items(intAdded).SubItems.Add(dt.Rows(intIndex).Item("task"))
lstTasks.Items(intAdded).SubItems.Add(dt.Rows(intIndex).Item("priority"))
lstTasks.Items(intAdded).Checked = False
End If
End If
datBoldDate = dt.Rows(intIndex).Item("dateof")
mcDate.AddBoldedDate(datBoldDate)
intIndex = intIndex + 1
Loop
mcDate.UpdateBoldedDates()
blnLoaded = True
End Sub
Save my new data:
VB.NET:
Private Sub SaveData()
Dim newRow As DataRow = ds.Tables("Todo").NewRow()
Dim dt As DataTable = ds.Tables("Todo")
Dim intIndex As Integer
Dim blnAddNew As Boolean
blnAddNew = True
intIndex = 0
Do While intIndex < dt.Rows.Count
If txtTask.Text = dt.Rows(intIndex).Item("task") And lblDate.Text = dt.Rows(intIndex).Item("dateof") Then
If fraAddTask.Text = "Add New Task" Then
MsgBox("Task name already exists!", MsgBoxStyle.Critical, "ToDo")
txtTask.Clear()
txtTask.Focus()
GoTo SameTaskName
Else
dt.Rows(intIndex).Item("details") = txtDetails.Text
dt.Rows(intIndex).Item("priority") = cboPriority.SelectedItem.ToString
blnAddNew = False
Exit Do
End If
End If
intIndex = intIndex + 1
blnAddNew = True
Loop
If blnAddNew = True Then
newRow("checked") = False
newRow("task") = txtTask.Text
newRow("details") = txtDetails.Text
newRow("dateof") = lblDate.Text
newRow("priority") = cboPriority.SelectedItem.ToString
ds.Tables("Todo").Rows.Add(newRow)
End If
daTodo.Update(dt)
fraAddTask.Visible = False
txtTask.Clear()
txtDetails.Clear()
cboPriority.SelectedIndex = -1
mcDate.Enabled = True
Exit Sub
SameTaskName:
End Sub
Remove current item selected in the listview:
VB.NET:
Private Sub mnuRemove_Click(sender As Object, e As EventArgs) Handles mnuRemove.Click
Dim dt As DataTable = ds.Tables("Todo")
Dim intRow As Integer
intRow = dt.Rows.IndexOf(dt.Select("task = '" & strTask & "'" & " AND dateof = '" & lblDate.Text & "'").FirstOrDefault)
If MsgBox("Delete task '" & dt.Rows(intRow).Item("task") & "'?", MsgBoxStyle.YesNo, " ToDo") = MsgBoxResult.Yes Then
dt.Rows(intRow).Delete()
daTodo.Update(dt) <--- [COLOR=#ff0000]ERROR OCCURS HERE![/COLOR]
LoadData()
Else
End If
End Sub