Describe two uses of the “using” statement during the operation of C#

devquora
devquora

Posted On: Feb 22, 2018

 

The “using” statement in C# is used:

  • To import a namespace. The following coding is coded:

using System;

using System. Collections.Generic;

using System. ComponentModel;

using System. Data;

using System. Drawing;

using System. Linq;

using System. Text;

using System. Threading, Tasks;

using System. Windows. Forms;

using System. Data. OLEDB;

  • To close a running connection efficiently. The following coding is used:
  • using System;
  • using System. Collections.Generic;
  • using System. ComponentModel;
  • using System. Data;
  • using System. Drawing;
  • using System. Linq;
  • using System. Text;
  • using System. Threading, Tasks;
  • using System. Windows. Forms;
  • using System. Data. OLEDB;

namespace WindowsFormsApp1

 
{ 
   public partial class Form1: Form 
    { 
    public Form1() 
    { 
      InitializeComponent(); 
     } 
      private void Form1_Load(object sender, EventArgs e) 
    { 
       String constr = “Provider=Microsoft.ACE.OLEDB.12.0;} + 
        “Data Source=***” + 
         “Jet OLEDB: Database Password=***”; 
        using (OLEDBConnection con = new OLEDBConnection (constr)) 
    { 
       con.Open(); 
        MessageBox.Show(“Connection is Opened!);
      }
     }
   }
 }

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    ADO.Net Interview Questions

    Describe ADO.net?

    ADO.net is an acronym for ActiveX Data Objects, which is commonly used as a part of the .net framework...

    ADO.Net Interview Questions

    List some of the common data providers for ADO.net framework.

    Some of the common data providers for ADO.net framework include:..