Hi, I am having a problem with editing/updating my program in visual basic. It does not seem to update my access database.
Can someone please assist me?
This is an error I get when trying to UPDATE a field :
"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in BMS College.exe
Additional information: The record cannot be deleted or changed because table 'ASSESMENT' includes related records."
Also when I click the SAVE button, the data does not get added to the ACCESS Database.
This is the code for one of my forms :
Dim cnn As New OleDb.OleDbConnection
Private Sub HelpToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem1.Click
MessageBox.Show("Please consult our Teckies.")
End Sub
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
About.ShowDialog()
End Sub
Private Sub ToolStripTextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripTextBox1.Click
First_form.Close()
End Sub
Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
Me.STUD_IDTextBox.Text = " "
Me.STUD_FNAMETextBox.Text = " "
Me.STUD_LNAMETextBox.Text = " "
Me.MEN_IDTextBox.Text = " "
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.StudentsTableAdapter1.Fill(Me.Access_database_of_BMSDataSet1.Students)
Me.StudentsTableAdapter1.Fill(Me.Access_database_of_BMSDataSet1.Students)
End Sub
Private Sub Exit3btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Exit3btn.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
Me.Validate()
Me.StudentsBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Access_database_of_BMSDataSet1)
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
Me.STUD_IDTextBox.Text = " "
Me.STUD_FNAMETextBox.Text = " "
Me.STUD_LNAMETextBox.Text = " "
Me.MEN_IDTextBox.Text = " "
End Sub
Private Sub StudentsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.StudentsBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Access_database_of_BMSDataSet1)
End Sub
Private Sub BtnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEdit.Click
Me.Validate()
Me.StudentsBindingSource.AddNew()
Me.TableAdapterManager.UpdateAll(Me.Access_database_of_BMSDataSet1)
End Sub
Private Sub Btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btndelete.Click
MsgBox("You are about to delete this record...", MsgBoxStyle.OkOnly)
Me.Validate()
Me.StudentsBindingSource.RemoveCurrent()
Me.TableAdapterManager.UpdateAll(Me.Access_database_of_BMSDataSet1)
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim str As String = TextBox1.Text
Try
If Me.TextBox1.Text.Trim(" ") = " " Then
Else
For i As Integer = 0 To StudentsDataGridView.Rows.Count - 1
For j As Integer = 0 To Me.StudentsDataGridView.Rows(i).Cells.Count - 1
If StudentsDataGridView.Item(j, i).Value.ToString().ToLower.StartsWith(str.ToLower) Then
StudentsDataGridView.Rows(i).Selected = True
StudentsDataGridView.CurrentCell = StudentsDataGridView.Rows(i).Cells(j)
Exit Try
End If
Next
Next i
End If
Catch abc As Exception
MessageBox.Show("Error : No Student Found!")
End Try
End Sub
Private Sub btnvp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvp.Click
Student_Information.Show()
End Sub
End Class