Msgbox是否&取消按钮在VB.NET 2010中工作
下面是我的MsgBox代码。“是”按钮正在工作,但当我单击“否”或“取消”时,它仍会删除数据Msgbox是否&取消按钮在VB.NET 2010中工作,vb.net,msgbox,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)", MsgBoxStyl
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()
单击“否”或“取消”时如何取消删除操作?使用基本If语句检查MsgBox的返回值。MsgBox本身不会取消任何操作
If MsgBox("Prompt", MsgBoxStyle.YesNoCancel, "Title") = MsgBoxResult.Yes Then
' execute command
End If
您还可以使用MsgBoxStyle.YesNo仅获取是和否按钮。使用基本If语句检查MsgBox的返回值。MsgBox本身不会取消任何操作
If MsgBox("Prompt", MsgBoxStyle.YesNoCancel, "Title") = MsgBoxResult.Yes Then
' execute command
End If
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
您也可以使用MsgBoxStyle.YesNo只获取是和否按钮。类似于If…Then,但我认为这更干净
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
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
类似于如果…那么,但我认为这更干净
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
MsgBox仍然不能在ASP.NET生产环境或QA而不是开发环境中工作。MsgBox仍然不能在ASP.NET生产环境或QA而不是开发环境中工作。顺便说一句,您应该使用.NET等效的System.Windows.Forms.MessageBox.Show而不是MsgBox。虽然它们都指向.NET版本,但我们已经转到.NET,没有什么理由保留VB6语法。顺便说一下,您应该使用与.NET等效的System.Windows.Forms.MessageBox.Show,而不是MsgBox。虽然它们都指向.NET版本,但我们已经转到.NET,没有什么理由保留VB6语法。