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;
        }


    }

  • 相关阅读:
    【NOIP2013】 华容道 bfs预处理+bfs
    【NOIP2017】逛公园 最短路+DP
    NOIP上机测试注意事项
    【NOIP2013】货车运输 最大生成树+倍增
    【NOIP2013】 火柴排队 贪心+splay
    【NOIP2013】转圈游戏 快速幂
    【xsy1143】 兔子的数字 搜索
    【xsy1172】 染色 dp
    【NOIP2017】 宝藏 状压dp
    【NOIP2017】列队 splay
  • 原文地址:https://www.cnblogs.com/Jace/p/1884327.html
Copyright © 2011-2022 走看看