Hi there,
I am currently writing a code that queries data from a MySQL database. Once I have that data, I want to let the user delete the current record he is looking at. So what I did was to place a textbox that will let the user input any search keyword and then select any search criteria he wants from a drop down box. When the user click on the find button, this code is executed"
CODE
Dim SearchBy As String = cmbSearchBy.SelectedItem
Dim searchKeyWord As String = txtSearch.Text
lblResults.Text = "Searching..."
Select Case SearchBy
Case "EmployeeName"
' records is a private object defined
' previously in the code
records = From employee In Me.Vendor_dbDataSet.employee _
Where employee.EmployeeName Like searchKeyWord & "*" _
Select employee
Case "EmployeeID"
records = From employee In Me.Vendor_dbDataSet.employee _
Where employee.EmployeeID Like searchKeyWord & "*" _
Select employee
End Select
Try
Me.EmployeeBindingSource.DataSource = records
lblCurrentPosition.Text = Me.EmployeeBindingSource.Position + 1 & _
" of " & Me.EmployeeBindingSource.Count.ToString
lblResults.Text = Me.EmployeeBindingSource.Count.ToString & " records found."
Catch ex As Exception
lblResults.Text = "No records found."
MessageBox.Show("No match found.", "Sorry", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End Try
This gives me the matches I want. They are shown one by one in the textbox, and I made a small navigation system for them. When the user finds the value he/she is looking for, he/she will have to press the delete button, and this code will be executed:
CODE
Try
Dim result As MsgBoxResult
Dim Count As String = Me.EmployeeBindingSource.Count.ToString
result = MessageBox.Show("Are you sure you want to delete " & _
Count & " record(s)? This cannot be undone.", _
"Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
If result = MsgBoxResult.Yes Then
' This actually removes the value from the list, but apparently it
' does not save it to the database permanently.
Me.Validate()
Me.EmployeeBindingSource.RemoveCurrent()
Me.EmployeeBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.AVendor_dbDataSet)
End If
MessageBox.Show("Record(s) deleted.", "Success", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
After I click on delete I get a confirmation asking if I want to do it, I go on and say yes, and the values are removed. If I search again for the same keywords, I will get the same record I just deleted. I am suspecting I am just taking some temporary value and deleting it, but I do not know how to deal with this case. I will greatly appreciate any help concerning this topic.
Thank you