删除VB.NET中的记录后无法刷新数据库 [英] Unable to refresh database after deleting a record in VB.NET

查看:122
本文介绍了删除VB.NET中的记录后无法刷新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub cmdDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDel.Click
     
        If MessageBox.Show("Are you sure?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.No Then
            MsgBox("Record Deletion Opearation Cancelled")
            Exit Sub
        End If
        Try
            ''STR = "DELETE FROM StdMasterNew WHERE '" & TextBox1.Text & "'=ID"
            ''STR = "DELETE FROM StdMasterNew WHERE ID='" & TextBox1.Text & "'"
            STR = "DELETE FROM StdMasterNew WHERE ID= " & TextBox1.Text & ""
            CMD = New OleDbCommand(STR, CON)
            CON.Open()
            CMD.ExecuteNonQuery()
            CON.Close()
            Me.Refresh()
            MsgBox("Existing Record Updated Successfully...")
        Catch
            If CON.State = ConnectionState.Open Then
                CON.Close()
            End If
            MessageBox.Show("Error Deleting data...")
            'MsgBox(ex.Message & " -  " & ex.Source)
            'MessageBox.Show(ex.Message)
        End Try
        CON.Open()
        STR = "SELECT * FROM StdMasterNew"
        CMD = New OleDbCommand(STR, CON)
        CMD.ExecuteNonQuery()
        CON.Close()

        'Moving to Last Record
        CurrentRow = DST.Tables("ClassMan").Rows.Count - 1
        ShowData(CurrentRow)
    End Sub





这是我的删除按钮代码。但是当我按下它时,记录会被删除,但是当我按下BACK,NEXT,FIRST,LAST按钮时显示。但是当我重新编译它时,记录被删除



我尝试过:



i尝试刷新了

Me.Refresh

但无用......



This is my Delete button code. But When I press it the record gets deleted but showing when I press BACK, NEXT, FIRST, LAST buttons. But when I re-compile it the record is deleted

What I have tried:

i have tried refreshing with
Me.Refresh
but useless...

推荐答案

好的,所以您删除了数据库中的记录,但没有刷新数据控件绑定的数据集以反映已删除的记录。将数据重新加载到您绑定到的控制结构中,记录将消失。
OK, so you deleted the record in the database but you didn't refresh the dataset your data controls is bound to to reflect the deleted record. Reload the data into the structure you've bound you controls to and the record will disappear.


这篇关于删除VB.NET中的记录后无法刷新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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