下面是我的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()
如何在点击否或取消时取消删除操作?
答案 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而不是开发环境中不起作用。