I use the following code to catch the SQL Expression, when i try to delete a primary key wich is also a foreign key and is mapped to another table, my question is, how do you forward this to a common error page ?
To catch the expression,
if(e.Exception is SqlException)
{
SqlException ex = (SqlException)e.Exception;
if (ex.Number == 547)
ErrorMessage("Record cannot be deleted or changed " +
"as it is being used somewhere else");
else if (ex.Number == 2627)
ErrorMessage("Record cannot be saved, as another " +
"record with this key already exists");
else
ErrorMessage(ex.Message.ToString());
}
else
ErrorMessage("System Error :"+e.Exception.Message.ToString());