检查datagridview中的行和列是否没有更改vb.net

时间:2016-12-26 00:45:53

标签: vb.net datagridview

如果没有更改,如何检入Datagridview,然后提示用户我的datagridview没有变化。我想在我的更新按钮中执行此操作以首先检查是否没有更改提示msgbox然后退出sub。怎么做?让我们说数据库中的数据已经加载到datagridview。

Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click

'this line is what I want for checking will happen if there is no changes in data happens in datagridview

        Dim row, id, dgvUnits As Integer
        Dim dgvYearLevel, dgvSemester, dgvCNo, dgvCDescription As String

        'Declared this variable to get value event click on dgv
        row = DataGridView1.CurrentRow.Index

        id = DataGridView1(6, row).Value
        dgvYearLevel = DataGridView1(1, row).Value
        dgvSemester = DataGridView1(2, row).Value
        dgvCNo = DataGridView1(3, row).Value
        dgvCDescription = DataGridView1(4, row).Value
        dgvUnits = DataGridView1(5, row).Value

        Try
            con.Open()

            With cmd
                .Connection = con
                .CommandText = "UPDATE tblcurriculumcourses SET YearLevel='" & dgvYearLevel & "', Semester='" & dgvSemester & "', CourseNo='" & dgvCNo & "', CourseDes='" & dgvCDescription & "', Units='" & dgvUnits & "' where PrimaryDummy='" & id & "'"
            End With
            cmd.ExecuteNonQuery()


            MsgBox("Data Has Been Successfully Update!")
        Catch ex As Exception
            MsgBox("Error when updating data")
        End Try

1 个答案:

答案 0 :(得分:0)

我没有合理的答案,但我有了一个主意。也许,你可以将DataGridView中的一行变暗为数组或字符串,稍后,在按钮上,您可以执行类似

的操作。
If DataGridView1(1, row).Value = TheArrayOrString Then
 'This is what you want it to do. Example:
   MsgBox("Your table is the same!")

也许,尝试类似的东西,你也必须选择DataGridView的所有行!它正在做的是,一旦你将DataGridView中的所有行都设置为ArrayList,你就可以测试它是否没有改变。所以'If DataGridView1(1,row).Valie = TheArrayOrString'正在测试DataGridView1表在一段时间内是否具有相同的内容。 'MsgBox(“你的桌子是一样的!”)'是自我解释的。希望这有助于传播你的想象力!玩得开心! :)

相关问题