Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 :

VB
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
        'TODO: This line of code loads data into the 'Access_database_of_BMSDataSet1.Students' table. You can move, or remove it, as needed.
        Me.StudentsTableAdapter1.Fill(Me.Access_database_of_BMSDataSet1.Students)
        'TODO: This line of code loads data into the 'Access_database_of_BMSDataSet.Students' table. You can move, or remove it, as needed.
        Me.StudentsTableAdapter1.Fill(Me.Access_database_of_BMSDataSet1.Students)
        ''cnn = New OleDb.OleDbConnection
        ''cnn.ConnectionString("provider'microsoft.jet.oledb.4.0;datasource'" & Application.StartupPath & "\data.mdb"



    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
        ''Dim cmd As New OleDb.OleDbCommand
        ''cnn.ConnectionString
        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
Posted
Updated 28-Apr-14 6:14am
v4
Comments
Nelek 28-Apr-14 10:39am    
How? Don't think we can read minds or do astral projections to see your monitor. If you need help, the least you could do is to add some relevant code to your question or to explain your problem in such a way, that the users of CP can understand it. Otherwise, nobody will be able to help you.

Please use the "improve question" and add relevant information or a piece of code envolved. There are thousands of ways to screw things up, how are we supposed to know which one did you choose?
Quwen Witbooi 28-Apr-14 11:03am    
It is my first time posting
Sergey Alexandrovich Kryukov 28-Apr-14 11:35am    
Do you think it makes it more understandable? :-)
—SA
Quwen Witbooi 28-Apr-14 12:01pm    
I haven't done this before, so could you please explain what I could use to make it more understandable?
Quwen Witbooi 28-Apr-14 12:15pm    
Is it possible to give me you email address?

1 solution

As per my understanding with all above conversation, I think its issue of referential integrity. You have relationship between two tables and you have set property that don't delete record from primary table when reference records are available in related tables. Check your referential integrity to fix it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900