日期:2011-05-25  浏览次数:20451 次

public class Intro:IDisposable
 {
  private OleDbConnection conn;
  private OleDbCommand cmd;
  private string IntroContent;

  public Intro()
  {
   conn=DBConnection.getConn();
   conn.Open();
   cmd=new OleDbCommand("select top 1 * from [Intro]",conn);
   try
   {
    OleDbDataReader dr=cmd.ExecuteReader();
    dr.Read();
    IntroContent=dr.GetValue(1).ToString();
   }
   catch
   {
    IntroContent="";
   }
   finally
   {
    cmd.Dispose();
    conn.Close();
   }
  } 

 public void Dispose()
  {
   if(conn.State==ConnectionState.Open)
    conn.Close();
   conn.Dispose();
   GC.SuppressFinalize(this);
  }

}

调用是-------

using(Intro it=new Intro())
   {

   }