主页 > 编程资料 > C# >
发布时间:2015-09-26 作者:网络 阅读:231次
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())
   {

   }

<> <>
关键字词: