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

First, thank you for your message.

I will have to review again your blog entries; it has been a while. What I was thinking (since I posted this message) is that I need to modify the method ExecuteCommand() of DAL to return True or False. And if False, set the error message to the property .ErrorMessage of DAL object. That way, UI can get the error message from the DAL object and deal with it. Therefore, I will need to change the code that Throws the error and rather just get the error message and return False. At least, this is how I do it in my VFP app. But maybe this is not the way things are done in .NET. I will, of course, re-read your blog and your suggestion in this message.

But I was thinking also that I need to learn how to deal with this "Throw" syntax. Would the code in UI have to catch the error that DAL Throws?

>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.
"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
Previous
Reply
Map
View

Click here to load this message in the networking platform