Click here to Skip to main content
15,904,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am creating a sample web application in which i have list of products that the user selected which has to be store in to the database..but if any of the particular products availability is less than that the user required i want to rollback the entire transaction.the list is like this.

List<Product> the product is a entity object which consist of product attributes such as Product name, availability,required etc.
please give me an idea.

Thanks in Advance.
Posted
Updated 21-Jun-11 18:52pm
v2

1 solution

The best way to achieve this is to put a check in your SP (stored procedure) itself. But if you want to do it in your application you should take help of TransactionScope class.
Here is a CP article which might help you to understand better.

Hope this helps.
 
Share this answer
 
Comments
varunmohan 22-Jun-11 1:47am    
thanks for ur response,but what i have done in my application is i have a list of products and i selected each product object using foreach loop and saved each product into sql server using a SP insert statement...in this scenario how can i make use of transaction
RakeshMeena 22-Jun-11 2:02am    
That means you are saving each product one by one?
If no then also it won't make a difference, you just need to keep your foreach loop inside the transactionscope.
If yes I would suggest that you save all the products at a once by converting the list of products into an xml and then passing it to the SP. There are plenty of examples that can help you in this regard, one of them is this.
varunmohan 22-Jun-11 2:18am    
Thanks a lot...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900