Msgbox是否&取消按钮在VB.NET 2010中工作

时间:2013-03-16 18:02:52

标签: vb.net msgbox

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

如何在点击取消时取消删除操作?

4 个答案:

答案 0 :(得分:5)

使用基本的If语句。 MsgBox不会取消任何内容。

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

您还可以使用MsgBoxStyle.YesNo仅获取“是”和“否”按钮。

答案 1 :(得分:2)

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

答案 2 :(得分:0)

        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

答案 3 :(得分:0)

仍然是一个MsgBox在ASP.NET生产环境或QA而不是开发环境中不起作用。