1

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

4 回答 4

6

使用基本If语句检查MsgBox. MsgBox不会自行取消任何内容。

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

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

于 2013-03-16T18:09:43.727 回答
3

类似于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
于 2013-03-17T02:07:45.143 回答
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
于 2013-03-16T18:57:37.497 回答
0

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

于 2013-11-15T10:10:53.933 回答