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.htmlIf 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.