Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Forms
Title:
How to deal with error on update?
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01454304
Message ID:
01454304
Views:
113
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
Next
Reply
Map
View