从数据集中删除后的空记录

时间:2015-04-11 10:49:28

标签: sql vb.net dataset

从表单中删除记录后,有一个空记录,直到关闭表单并重新打开它 下面是我的代码

Try

        Dim delrecord As String = "delete  from  unitinfo where unitCode = '" & txtUcode.Text & "' "
        Dim delcon As New SqlConnection(sqlcon)

        delcon.Open()
        Dim cmdsqldel As New SqlCommand(delrecord, delcon)
        cmdsqldel.ExecuteNonQuery()
        If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then

            Exit Sub
        Else

        End If
        delcon.Close()

    Catch ex As Exception

    End Try 

1 个答案:

答案 0 :(得分:0)

Try

        If MessageBox.Show("Do you really want to Delete this Record?",
 "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then

            Exit Sub
        Else
        Dim delrecord As String = "delete  from  unitinfo 
                               where unitCode = '" & txtUcode.Text & "' "
        Dim delcon As New SqlConnection(sqlcon)
        delcon.Open()
        Dim cmdsqldel As New SqlCommand(delrecord, delcon)
        cmdsqldel.ExecuteNonQuery()
        delcon.Close()
        MessageBox.Show("Record Successfuly Deleted")
        /* Here you should refresh your datagridview if you have or any thing else*/
        End If

    Catch ex As Exception
    MessageBox.Show(ex.Message)
    Finally 
    ' This line executes whether or not the exception occurs.'
    If delcon.State = ConnectionState.Open Then delcon.Close()

    End Try