Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to deal with error on update?
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
How to deal with error on update?
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01454304
Message ID:
01454304
Vues:
112
Hi,

How do you deal with cases when database update (SQL Server) fails (e.g. constraints)? Here is a code from the DAL class that updates the database (this is not my code; I borrowed it from a blog of a famous person here <g>):
       protected void SaveTable(DataTable Table, string SaveProc)    
        {        
            foreach (DataRow row in Table.Rows)
            {            
                this.SetAllParameters(row);
                this.ExecuteCommand(SaveProc);
            }    
        }

// The problem occurs in method ExecuteCommand.  And the ExecuteCommand method looks like this:
//  simplified
protected void ExecuteCommand(string StoredProcName)    
        {        

            try         
            {             
                this.oCommand.ExecuteNonQuery();
            }        
            catch (Exception ex)
            {
                // !! This is where I get the error that Breaks the code.  
                throw ex;
            }        
         }
What I would like is to be able to return the error message back to the UI layer to be displayed.

TIA for any suggestions.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform