ASP.NET - how to use a using block in this code?

Asked By balaji on 18-Aug-12 07:56 AM
public class Connection
{

      private SqlConnection conn;

          public Connection()
      {
       conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);
      }

  
 public SqlConnection Openconn()
      {
        if(conn.State == ConnectionState.Closed || conn.State == ConnectionState.Broken)
        {
          conn.Open();
        }        
        return conn;
      }

 public void ExecuteQuery(string txtQuery)
      {

        SqlCommand cmd = new SqlCommand();     
          cmd.Connection = Openconn();
          cmd.CommandText = txtQuery;
          cmd.CommandTimeout = timeout;
          cmd.ExecuteNonQuery();     
      }
public SqlConnection Close()
      {
       if (conn.State == ConnectionState.Open)
        {
          conn.Close();
        }
        return conn;      
      }

}
Peter Bromberg replied to balaji on 18-Aug-12 09:44 AM
using (Sqlconnection OpenConn() )
{

your code here



}