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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15452725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 16:45:22  来源:igfitidea点击:

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

vb.netmsgbox

提问by CrashOverride

Below is my code for a MsgBox. The Yesbutton is working, but when I click Noor Cancelit still deletes the data...

下面是我的 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()

How do I have it cancel the delete operation when clicking Noor Cancel?

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

回答by PurkkaKoodari

Use the basic Ifstatement to check the return value of MsgBox. The MsgBoxdoesn't cancel anything by itself.

使用基本If语句检查 的返回值MsgBox。在MsgBox本身不取消任何东西。

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

You could also use MsgBoxStyle.YesNoto get only the Yes and No buttons.

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

回答by djv

Similar to If...Then, but I think this is cleaner

类似于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

回答by Vijay

Still a MsgBox will not work in an ASP.NET production environment or QA rather than development environment.

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

回答by CrashOverride

        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