A concept for custom error message with constraint.

  • Just playing around and thought this might be an interesting way to do it. Of course there are limitations and probably a better choice of surrounding characters but if anyone wants to input or just needs something that might help a bit take a look.


    Say you have a scheduling table and had a constraint to verify the effective dates for the schedule taht the start is less than the end so a reverse cannot be entered. Name it like so:

     

    CK_[Schedule_ActvieDate_Must_Be_Less_Than_EndDate]


    Now in your VB or ASP page do soemthing like this to catch the error and display the bracketed text only.

     

    If err <> 0 Then

    Dim ErrMsg

    ErrMsg = Replace(Mid(Err.Description, InStr(1,Err.Description,"[") + 1, InStr(1,Err.Description,"]") - InStr(1,Err.Description,"[") - 1),"_"," ")

    Response.Write ErrMsg

    Response.End

    End If

    On Error Goto 0


    So now you get output like so for your users

     

    Schedule ActvieDate Must Be Less Than EndDate


    Basically you now have provided a custom message for a constraint where you currently cannot use raiserror and elminiated the need to do thru other methods such as trigger or in whatever code checks.

    Just concept code for fun, would love everyones feedback.

  • This was removed by the editor as SPAM

  • lcase all the words but the first one and the user won't notice what you are doing 😉

  • Yeah using proper casing the string would be better. Thanks for the input.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply