我有一个特定的网络表单,当用户点击
保存按钮它调用我的dbEngineClass中的函数 save() 。
现在,当用户输入重复数据时,我会引发某个错误并在网页中处理它
显示某个消息框,但之后我希望它退出课程而不是这样做
还要别的吗
但显然它将继续执行btnsave.click sub
如果出现错误,我如何退出课程或阻止单击方法继续?
这是我的代码:这是保存信息并引发事件的函数
Public Sub SaveNewCustomer(ByVal Name As String, ByVal Tel1 As String, ByVal Tel2 As String, ByVal Email As String, ByVal Address As String, ByVal Coupon As String, ByVal Location As String, ByVal ParamLangaugeID As String, ByVal UserName As String)
Dim UserNameID As Integer = GetUserNameID(UserName)
conn = New SqlConnection(My.Settings.CustomerInfoNayefPc)
conn.Open()
cmd = New SqlCommand(String.Format("Insert into tblCustomerInfo (Name,Tel1,Tel2,Email,Address,CouponNo,Location,LangaugeID,UserNameID) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}',{7},{8})", Name, Tel1, Tel2, Email, Address, Coupon, Location, ParamLangaugeID, UserNameID))
cmd.Connection = conn
Try
cmd.ExecuteNonQuery()
Catch CouponNosqlexc As SqlException
RaiseEvent DuplicateErr()
End Try
这是我在网页中处理它的方式
Private Sub MydbEngine_DuplicateErr() Handles MydbEngine.DuplicateErr
Dim strMsg As String = "Duplicate Value exist"
Dim lbl As New Label
lbl.Visible = True
lbl.Text = "<script language='javascript'>" & Environment.NewLine _
& "window.alert(" & "'" & strMsg & "'" & ")</script>"
Page.Controls.Add(lbl)
End Sub
conn.Close()
End Sub
现在,在此处理程序完成后,我需要它退出并且不要继续 btnSave.click
调用SaveNewCustomer() 子的处理程序,因为当它继续时它会清除所有
数据,我不想要那个