transaction scope in c#

3
1
2
using(TransactionScope ts = new TransactionScope())
            {
                SqlConnection cn = new SqlConnection(@”data source = MNGKARGOPC\SQL2014EXP;database=YETKILENDIRME;integrated security=true;”);
                SqlCommand cmd1 = new SqlCommand(“insert into IL (CD_IL_KOD,CH_IL_AD) values (66000,’Melih’)”,cn);
                SqlCommand cmd2 = new SqlCommand(“insert into IL (CD_IL_KOD,CH_IL_AD) values (55000,’Melih’)”, cn);
                SqlCommand cmd3 = new SqlCommand(“insert into IL (CD_IL_KOD,CH_IL_AD) values (77000,’Melih’)”, cn);
                SqlCommand cmd4 = new SqlCommand(“update IL set CD_IL_KOD = 88000 WHERE CD_IL_KOD = 66000”, cn);
                SqlCommand cmd5 = new SqlCommand(“update IL set CD_IL_KOD = 7000 WHERE CD_IL_KOD = 4000 AND CF_ADS = ‘MK'”, cn);
                try
                {
                    cn.Open();
                    cmd1.ExecuteNonQuery();
                    cmd2.ExecuteNonQuery();
                    cmd4.ExecuteNonQuery();
                    cmd3.ExecuteNonQuery();
                    cmd5.ExecuteNonQuery();
          ts.Complete();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(“Hata Oluştu..: ” + ex.Message);
                }
                finally
                {
                    cn.Close();
                }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: