在Visual Basic中编辑/更新我的程序的问题 [英] problem with editing/updating my program in visual basic

查看:133
本文介绍了在Visual Basic中编辑/更新我的程序的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Basic中编辑/更新程序时遇到问题。它似乎没有更新我的访问数据库。



有人可以帮助我吗?



这是我在尝试更新字段时遇到的错误:

BMS College.exe中发生了'System.Data.OleDb.OleDbException'类型的未处理异常



附加信息:记录无法删除或更改,因为表'ASSESMENT'包含相关记录。



此外,当我单击SAVE按钮时,数据不会添加到ACCESS数据库。



这是我的一个表格的代码:



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
        '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

推荐答案

根据我对上述所有对话的理解,我认为它的参照完整性问题。您有两个表之间的关系,并且您具有set属性,当相关表中的引用记录可用时,该属性不会从主表中删除记录。检查您的参照完整性以修复它。
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.


这篇关于在Visual Basic中编辑/更新我的程序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆