tags:

views:

35

answers:

2

We normally use these statements to add anew record to database.

MyDataContext.InsertOnSubmit(AnObject);
MyDataContext.SubmitChanges();

Other than using stored procedure(can return a value by "Return / Output"), is there a way to return a value indicating, operation was successful ? probably, Linq own methods / functions

Any idea, Thanks

+1  A: 

Couldn't use a try and catch block and trap the appropriate errors?

Ralph Stevens
Thanks for reply, It is not about failing a transaction, actually want to check an operation was successful, like doing an Update. It might not update and not fail either...
Asad Butt
You would get an exception related to the update operation failure.
Ralph Stevens
+4  A: 

If the operation is not successful, then it will throw an exception. If it doesn't throw an exception, then it was successful.

John Saunders
Any particular exception ?
Asad Butt
`System.Data.SqlClient.SqlException`
Alex Bagnolini
Thanks mate, do appriciate
Asad Butt
Whatever exception caused the operation to fail. I would not assume it would be `SqlException`.
John Saunders