zoukankan      html  css  js  c++  java
  • 个人编写的一个简单的DB类

    这个是我写的一个比较初级的DB类,主要是把对数据库的一些操作封装起来
    public class DB
    {
        OleDbConnection conn;
        OleDbCommand cmd ;
       
        public DB()
        {    
            conn = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath(@"~/App_Data/sj.mdb"));
            cmd = new OleDbCommand();
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        public OleDbConnection open()
        {
          
            if (conn.State == ConnectionState.Closed)
                conn.Open();
            return conn;
        }

        public void close()
        {
            if (conn.State == ConnectionState.Open)
                conn.Close();

        }

        public DataSet getDataSet(string strOleDb)
        {
            open();
            OleDbDataAdapter dr = new OleDbDataAdapter(strOleDb, conn);
            DataSet ds = new DataSet();
            dr.Fill(ds);
            return ds;
            close();
        }

    /*    public OleDbDataReader getDataReader(string strOleDb)
        {
            cmd.Connection = open();
            cmd.CommandText = strOleDb;
            OleDbDataReader sdr = cmd.ExecuteReader();
            return sdr;
            close();

        }*/

        public bool execute(string strOleDb)
        {
            // bool flag=false;
            cmd.Connection = open();
            cmd.CommandText = strOleDb;
            int a= cmd.ExecuteNonQuery();
            close();
           /* if (a > 0)
            {
                flag = true;
            }
            return flag;
            */

            return a > 0 ? true : false;
          
       
        }

        public string ExecuteScalar(string strOleDb)
        {
            cmd.Connection = open();
            cmd.CommandText = strOleDb;
            string result = cmd.ExecuteScalar().ToString();
            close();
            return result;
        }


    }

  • 相关阅读:
    URAL 2067 Friends and Berries (推理,数学)
    URAL 2070 Interesting Numbers (找规律)
    URAL 2073 Log Files (模拟)
    URAL 2069 Hard Rock (最短路)
    URAL 2068 Game of Nuts (博弈)
    URAL 2066 Simple Expression (水题,暴力)
    URAL 2065 Different Sums (找规律)
    UVa 1640 The Counting Problem (数学,区间计数)
    UVa 1630 Folding (区间DP)
    UVa 1629 Cake slicing (记忆化搜索)
  • 原文地址:https://www.cnblogs.com/Jace/p/1884327.html
Copyright © 2011-2022 走看看