Updating Data Using Transactions : SqlTransaction : ADO.Net C# Examples


C# Examples » ADO.Net » SqlTransaction »

 

Updating Data Using Transactions









    
using  System;
using  System.Data;
using  System.Data.SqlClient;


class  MainClass
{
    static  void  Main(string[]  args)
    {
        SqlConnection  MyConnection  =  new  SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated  Security=SSPI;");

        MyConnection.Open();

        String  MyString  =  "INSERT  INTO  Employee(ID,  FirstName)VALUES(1,  'Greg')";
        SqlTransaction  MyTransaction  =  MyConnection.BeginTransaction();
        SqlCommand  MyCmd  =  new  SqlCommand(MyString,  MyConnection,  MyTransaction);

        MyCmd.ExecuteScalar();
        MyTransaction.Commit();
        MyConnection.Close();
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo ADO.Net
» SqlTransaction