OleDb数据层C#代码


public class Conn
 {
  public OleDbConnection my_Conn;

  public static string strConn
  {
   get
   {
    StringBuilder builder1 = new StringBuilder();
    builder1.Append("Provider = Microsoft.Jet.OLEDB.4.0");
    builder1.Append("; ");
    builder1.Append("Data Source = ");
    builder1.Append(HttpContext.Current.Server.MapPath("."));
    builder1.Append(@"\");
    builder1.Append(ConfigurationSettings.AppSettings["DataPath"]);
    return builder1.ToString();
   }
  }

  public void DBopen()
  {
   if (this.my_Conn.State == ConnectionState.Closed)
   {
    this.my_Conn.Open();
   }
  }

  public void DBclose()
  {
   if (this.my_Conn.State == ConnectionState.Open)
   {
    this.my_Conn.Close();
   }
  }

  public DataSet CreateDataSet(string strSql, string tableName)
  {
   OleDbDataAdapter adapter1 = new OleDbDataAdapter(strSql, this.my_Conn);
   DataSet set1 = new DataSet();
   adapter1.Fill(set1, tableName);
   return set1;
  }

  public int ExecuteSql(string strSql)
  {
   OleDbCommand command1 = new OleDbCommand(strSql, this.my_Conn);
   return command1.ExecuteNonQuery();
  }

  public OleDbDataReader ExecuteOleDbDataReader(string strSql)
  {
   OleDbCommand command1 = new OleDbCommand(strSql, this.my_Conn);
   return command1.ExecuteReader();
  }


  public Conn()
  {
   this.my_Conn = new OleDbConnection(Conn.strConn);
  }
 }

posted @ 2005-08-02 13:46  therockthe  阅读(839)  评论(0)    收藏  举报