繁体   English   中英

Msgbox Yes No & 在 VB.NET 2010 中工作的取消按钮

[英]Msgbox Yes No & cancel button working in VB.NET 2010

下面是我的 MsgBox 代码。 是”按钮正在工作,但是当我单击“否”或“取消”时,它仍会删除数据...

        strup = "DELETE FROM student WHERE urno =" & CInt(txtUrn.Text) & ";"
        Dim command As New OleDb.OleDbCommand(strup, con)
        MsgBox("Do you want to delete record(s)", MsgBoxStyle.YesNoCancel, "Confirm Delete")
        command.ExecuteNonQuery()
        con.Close()

单击NoCancel时如何取消删除操作?

使用基本的If语句检查MsgBox的返回值。 MsgBox本身不会取消任何内容。

If MsgBox("Prompt", MsgBoxStyle.YesNoCancel, "Title") = MsgBoxResult.Yes Then
    ' execute command
End If

您还可以使用MsgBoxStyle.YesNo来仅获取 Yes 和 No 按钮。

类似于If...Then ,但我认为这更干净

Select Case MsgBox("Are you sure ?", MsgBoxStyle.YesNo, "Delete")
    Case MsgBoxResult.Yes
        ' Do something if yes
    Case MsgBoxResult.No
        ' Do something if no
End Select
        If MsgBox("Are you sure ?", MsgBoxStyle.YesNo, "Delete") = MsgBoxResult.Yes Then
            strup = "DELETE FROM student WHERE urno =" & CInt(txtUrn.Text) & ";"
            Dim command As New OleDb.OleDbCommand(strup, con)
            'MsgBox("Do you want to delete record(s)", MsgBoxStyle.YesNoCancel, "Confirm Delete")
            command.ExecuteNonQuery()
            con.Close()
            txtUrn.Text = ""
            txt10Per.Text = ""
            txt12Per.Text = ""
            txtCAdd.Text = ""
            txtEid.Text = ""
            txtFname.Text = ""
            txtGPer.Text = ""
            txtMno.Text = ""
            txtName.Text = ""
            txtPAdd.Text = ""
            cmb10YofPass.Text = ""
            cmb12YofPass.Text = ""
            cmbDate.Text = ""
            cmbGender.Text = ""
            cmbMonth.Text = ""
            cmbNameofGCourse.Text = ""
            cmbYear.Text = ""
            ComboBox1.Text = ""
            TextBox1.Text = ""
            MsgBox("Record Deleted Successfully")
        ElseIf MsgBoxResult.No Then

        End If

MsgBox 仍然不能在 ASP.NET 生产环境或 QA 而不是开发环境中工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM