DataClasses1DataContext dc = new DataClasses1DataContext();
var Q = from p in dc.Customers where p.id > 4 select p;
foreach (var q in Q)
q.totalpurchase = 100;
var Q2 = from p in dc.Customers where p.id < 4 select p;
foreach (var q in Q2)
q.totalpurchase = 500;
dc.SubmitChanges();
SqlTransaction tran = null;
try
{
tran = con.BeginTransaction(IsolationLevel.ReadUncommitted);
dc.Transaction = tran;
var Q3 = from p in dc.Customers where p.id > 4 select p;
foreach (var q in Q3)
q.totalpurchase = 100;
var Q4 = from p in dc.Customers where p.id < 4 select p;
foreach (var q in Q4)
q.totalpurchase = 500;
dc.SubmitChanges();
SqlCommand cmd = new SqlCommand(@"update
Customers set totalpurchase=totalpurchase+0.10
where cname='Franek'", con,tran);
cmd.ExecuteNonQuery();
System.Threading.Thread.Sleep(20000);
SqlCommand cmd2 = new SqlCommand(@"update
Customers set totalpurchase=totalpurchase-0.10
where cname='Janek'", con, tran);
cmd2.ExecuteNonQuery();
tran.Commit();
textBox1.Text = "done";
}
catch(Exception ex)
{
tran.Rollback();
textBox1.Text = ex.Message;
}