Create a SqlCommand : SqlCommand : ADO.Net C# Examples


C# Examples » ADO.Net » SqlCommand »

 

Create a SqlCommand









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

class  MainClass
{
      static  void  Main()
      {
            SqlConnection  conn  =  new  SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated  Security=SSPI;");

            SqlCommand  cmd  =  new  SqlCommand();
            Console.WriteLine("Command  created.");

            try
            {
                  conn.Open();
            }
            catch  (SqlException  ex)
            {
                  Console.WriteLine(ex.ToString());
            }
            finally
            {
                  conn.Close();
                  Console.WriteLine("Connection  Closed.");
            }
      }
}
    
   
  
   



Output

Command created.
Connection Closed.


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo ADO.Net
» SqlCommand