基类中的一些常用函数.

public class FileRight:IDisposable
 {
  private SqlDataAdapter dsCommand;
  public SqlConnection mySqlConnection;
  public static  string CONN;
  
  public FileRight()
  {
   CONN=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
   mySqlConnection = new SqlConnection(CONN);
  }

  public void Dispose()
  {
   Dispose(true);
   GC.SuppressFinalize(true);
  }

  protected virtual void Dispose(bool disposing)
  {
   if (! disposing)
    return;

   if (dsCommand != null)
   {
    if(dsCommand.SelectCommand != null)
    {   
     if( dsCommand.SelectCommand.Connection != null )
      dsCommand.SelectCommand.Connection.Dispose();
     dsCommand.SelectCommand.Dispose();
    }   
    dsCommand.Dispose();
    dsCommand = null;
   }
  }
......
}

原文地址:https://www.cnblogs.com/lingxzg/p/453464.html