Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: LINQ C#4.0
I an new in linq i want to use commit rollback tsql in linq using c# 4.0
Posted 15-May-12 22:14pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

before any changes occure on the database you have to have a db.submitchanges() before the changes are submitted. Anything that happens in the mean-time will be held in a transaction anyway. :
public void ChangeData(string newData)
            //Always use a new instance of the DataContext when making changes to the data as all changes made would be submitted otherwise
            DataContext1 db = new DataContext1();
            //throws an error if it find 0 or >1 record.  can be useful
            data recordToUpdate = db.datas.Where(d => d.data_id == id).Single();
            //change data in the record instance.  Remember that this record is tied to the db instance of the database.  No other instance contains this change
            recordToUpdate.email_address = newData;
                //you could leave out the try and catch the error higher up
                //notify? raise error?
  //once db loses scope the changes vanish with it
Just remember that with link to sql, no actual changes happen until you try to submit the changes to that db instance
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

If I understood the question correctly, you should use the TransactionScope Class[^]

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

  Print Answers RSS
0 Maciej Los 585
1 OriginalGriff 458
2 CPallini 239
3 Sergey Alexandrovich Kryukov 175
4 Peter Leow 175
0 OriginalGriff 6,092
1 Sergey Alexandrovich Kryukov 4,898
2 Maciej Los 3,159
3 Peter Leow 3,129
4 DamithSL 2,490

Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 13 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100