CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> .NET

 Custom Error after Insert/update

Print topic Send  topic

Author Message
kristiano

Posts: 6
Posted: 09/08/2009, 2:38 AM

How to display a custom error after insert or update operation?
e.g.
after inserting a new user (if no error occurs) i want to send an email. if sending the mail fails i want to display an error message in the error label of the user form.
any idea?
View profile  Send private message
Vasiliy

Posts: 378
Posted: 09/09/2009, 11:06 AM

There are 2 options:

- for all SQL errors: find "App_Code\components\RecordDataProviderBase.vb"
change code:
______________
Protected Function ExecuteInsert() As Object
PrepareInsert()
If CmdExecution Then
Try
Return Insert.ExecuteNonQuery()
Catch ex As Exception
Throw New Exception(CreateFriendlyErrorMessage(ex))
End Try
Else
Return 0
End If
End Function

Protected Overridable Sub PrepareUpdate()
End Sub

Protected Function ExecuteUpdate() As Object
PrepareUpdate()
If CmdExecution And IsParametersPassed Then
Try
Return Update.ExecuteNonQuery()
Catch ex As Exception
Throw New Exception(CreateFriendlyErrorMessage(ex))
End Try
Else
Return 0
End If
End Function

Protected Overridable Sub PrepareDelete()
End Sub

Protected Function ExecuteDelete() As Object
PrepareDelete()
If CmdExecution And IsParametersPassed Then
Try
Return Delete.ExecuteNonQuery()
Catch ex As Exception
Throw New Exception(CreateFriendlyErrorMessage(ex))
End Try
Else
Return 0
End If
End Function
______________

Add in the same file within the class error handler:
______________
' Process DB Errors ---------------------------------------
Private Function CreateFriendlyErrorMessage(ByVal ex As Exception) As String

If System.Web.HttpContext.Current.Session("DeveloperMode") <> 1 Then
If Regex.IsMatch(ex.Message, "INSERT statement conflicted with") Then
Return "This Record is already in the database."
ElseIf Regex.IsMatch(ex.Message, "UPDATE statement conflicted with") Then
Return "This Record is used in other tables and can not be updated."
ElseIf Regex.IsMatch(ex.Message, "DELETE statement conflicted with") Then
Return "This Record is used in other tables and can not be deleted."
ElseIf Regex.IsMatch(ex.Message, "Cannot insert duplicate key.") Then
Return "This Record is already in the database."
ElseIf Regex.IsMatch(ex.Message, "Cannot insert the value") Then
Return "Please, fill all required fields."
ElseIf Regex.IsMatch(ex.Message, "The transaction ended in the trigger. The batch has been aborted.") Then
Return ex.Message.Replace("The transaction ended in the trigger. The batch has been aborted.","")
End If
End If
Return ex.Message
End Function
' Process DB Errors -----------------------------------end-
______________




- for a specific page, add an error handler AfterExecuteInsert/Update/Delete.
Example:
'Record LoanCustomDataStructure Event AfterExecuteUpdate. Action Custom Code @199-73254650
' -------------------------
' Write your own code here.
If Not IsNothing(E) Then Throw New Exception("Error converting data type.")
' -------------------------

_________________
Vasiliy
View profile  Send private message
kristiano

Posts: 6
Posted: 09/10/2009, 2:55 AM

Thank You for your answer - i will try it!
View profile  Send private message
Tuong Do
Posted: 11/05/2009, 3:52 PM

Hi Kristiano,

If your form name is MYFORM then

in the the after insert event just add the line

MYFORMErrors.Add("Sendmail_", "Error sending mail")



"kristiano" <kristiano@forum.codecharge> wrote in message
news:84aa626296df8e@news.codecharge.com...
> How to display a custom error after insert or update operation?
> e.g.
> after inserting a new user (if no error occurs) i want to send an email.
> if
> sending the mail fails i want to display an error message in the error
> label of
> the user form.
> any idea?
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>


Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.