Update data using SQL update clause : IDbCommand : ADO.Net C# Examples


C# Examples » ADO.Net » IDbCommand »

 

Update data using SQL update clause









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

class  MainClass
{
        public  static  void  Main()
        {
                using  (SqlConnection  con  =  new  SqlConnection())
                {
                        con.ConnectionString  =  "server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated  Security=SSPI;";
                        con.Open();

                        //  Create  and  configure  a  new  command.
                        IDbCommand  com  =  con.CreateCommand();
                        com.CommandType  =  CommandType.Text;
                        com.CommandText  =  "UPDATE  Employee  SET  FirstName  =  'S'"  +
                                "  WHERE  Id  =  '5'";
        
                        //  Execute  the  command  and  process  the  result.
                        int  result  =  com.ExecuteNonQuery();
        
                        if  (result  ==  1)
                        {
                                Console.WriteLine("Employee  title  updated.");
                        }
                        else
                        {
                                Console.WriteLine("Employee  title  not  updated.");
                        }
                }
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo ADO.Net
» IDbCommand