Presenting Error Messages

  • Thread starter Thread starter Todd Scott
  • Start date Start date
T

Todd Scott

Does anyone have a suggestion on how to present error
messages in a "user-friendly" way. I know how to "handle"
exceptions but what I want to do (at a minimum) is present
useful feedback to the user rather than a cryptic,
technical looking error message. For instance, if I
update a table (using SQLDataAdapter.UPDATE()) and it
returns a "Violation of UNIQUE KEY constraint..." message
I want to tell the user:

"User name entered already selected. Please select
another"

and not:

"Violation of UNIQUE KEY
constraint 'IX_Customer_Duplicate_User_Name'. Cannot
insert duplicate key in object 'Customer'.Source: .Net
SqlClient Data Provider"

I can not find a way to find out what constraint was
violated or what columns caused the error. I guess I
could parse the error message and then "hard-code" a
switch statement but that is not very "scalable"
or "object oriented".

Any suggestions?
 
Hi

Try in the following way:

Try
{//Code which generates Exception}
Catch(SQLException sqlexp)
{
sqlexp.Number //This number corresponds to an entry in
the master.dbo.sysmessages table.
//depeding on the Number give friendly error message

}


Ravikanth
 
Thank you but that would not allow me to specify the column name(s)
that caused the violation. In fact, it would just present the
"skeleton" for the message that already appears.
 
Back
Top