I am pretty new with ASP.NET and SQL Server so please provide support as much detail as possible, I really appreciate it. Here is my situation:
I am doing the registration system for the website using ASP.NET and SQL Server 2012 Express.
So when user registering, first of all, they need to fill out account information (name, address, phone, email, password...) and secondly, they need to fill the company information - where they are working at (company name, company industry, website, description...). So in database I have 2 table: User and Company
Problem is when they filled out all those require fields in the registration form and click SUBMIT button, how do I check if data has been inserted to 2 tables successfully, because if for any reason after data inserted to User table successfully but failed to Company table so this gonna be a problem, I don't know if there is any way to check it or reverse the process in SQL Server if any inserting query is failed.
I don't know this make sense for all of you, please ask me if you don't understand my question.
Thank you!
Without any code this is hard to answer.
In .net you can use Try{} catch{}
blocks to handle errors and act upon them.
A better approach is to Commit the User and Company in one transaction. This is dependent on your data access approach. In Linq2Sql you need to have the two insertions in one SubmitChanges() for example. Or do it yourself with TransactionScope
http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx
Update: read the Remarks in the link:
The System.Transactions infrastructure provides both an explicit programming model based on the Transaction class, as well as an implicit programming model using the TransactionScope class, in which transactions are automatically managed by the infrastructure.