Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to deal with error on update?
Message
From
13/03/2010 12:41:43
 
 
To
13/03/2010 11:12:30
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01454304
Message ID:
01454308
Views:
59
Hi Dmitry,

Thanks for referring to me as "famous". <g>

So, if you used my example totally as your DAL, then you probably had to tweak it a bit (for lurkers, I believe Dmitry is referring to Part III of my DataAccess series: http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-iii.html).

I noticed in the Start() method that it handles exceptions by this statement:
this.AddToErrorMessage(e);
And of course there is no AddToErrorMessage() method in my example. There is, however, an ErrorMessage property in the original BBDataAccess class shown in Part II: http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-ii.html

If your Start() method returns a false, you should be able to access the ErrorMessage property and do something with it, like return it to your UI.

Does this help?

~~Bonnie


>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.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform