Returning a record count after Delete of Businessobject

Returning a record count after Delete of Businessobject

Old forum URL: forums.lhotka.net/forums/t/2882.aspx


Mahmud posted on Wednesday, May 16, 2007

In our business class we want the following functionality -

In the DELETE button click event, we first delete the oject by calling

WorkorderBusinessClass.DeleteWorkorder(int id)

Immediately after the method returns we want to check whether the delete was successful. But, as the method is static - we cannot return any value. We have set one property in  the class 'boolen RecordsAffected' which can hold how many records were affected by the last query. But as the Delete method is static, we cannot set the value.

We need this, because - based on succss of the operation- we will set some visual cues in the form, and also delete a tree node corresonding the object.

 

 

 

JoeFallon1 replied on Wednesday, May 16, 2007

If the call returns without an exception then you know it succeeded so you can proceed from there.

Use a Try Catch block and call Delete.If there is no exception, set your visual cues and delete the tree node.

Joe

 

Mahmud replied on Thursday, May 17, 2007

This is not true in all scenario. If you send a DELETE SQL to any database, and if no record is deleted due to any reason (say, criteria mismatch) - then its not an error. So, just after the delete command inside the database - you have to return ROWCOUNT (in case of Oracle). Then out from the stored procedure - you have to check how many records were affected by the last query.

So, I do have the need to return a record count to front end - somehow. Anyone have any other idea?

xal replied on Thursday, May 17, 2007

You can either raise an error from the sproc or read the count in your DataPortal_Delete and if it's 0, then throw an exception.

Andrés

Copyright (c) Marimer LLC