• AccessHelper 需修改


    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Data.OleDb;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Web;
    
    namespace CyObject.BLL
    {
        public class DataAccessDAL
    
        {
            protected static OleDbConnection conn = new OleDbConnection();
            protected static OleDbCommand comm = new OleDbCommand();
            public DataAccessDAL()
            {
                //init
            }
    
            /// <summary>
            /// 打开数据库
            /// </summary>
            private static void openConnection()
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.ConnectionString = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" +System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["myconn"]);//web.config文件里设定。             
                    comm.Connection = conn;
                    try
                    {
                        conn.Open();
                    }
                    catch (Exception e)
                    { throw new Exception(e.Message); }
    
                }
    
            }
    
            /// <summary>
            /// 关闭数据库
            /// </summary>
            private static void closeConnection()
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                    conn.Dispose();
                    comm.Dispose();
                }
            }
            public static object ExecuteScalar(string sql, params OleDbParameter[] parameters) {
                openConnection();
                comm.CommandText = sql;
                comm.Parameters.AddRange(parameters);
                return comm.ExecuteScalar();
            }
    
            public static int ExecuteNonQuery(string sql, params OleDbParameter[] parameters) {
                openConnection();
                comm.CommandText = sql;
                comm.Parameters.AddRange(parameters);
                return comm.ExecuteNonQuery();
            }
    
            public static DataTable ExecuteDataTable(string sql, params OleDbParameter[] parameters) {
                openConnection();
                comm.CommandText = sql;
                comm.Parameters.AddRange(parameters);
                DataSet dataset = new DataSet();
                OleDbDataAdapter apdater = new OleDbDataAdapter(comm);
                apdater.Fill(dataset);
                return dataset.Tables[0];
            }
    
        }
    }
    

      

  • 相关阅读:
    最短路-dij
    链式前向星
    B树、B+树
    C++类
    差分约束
    数位DP
    Markdown编辑器:表格
    git使用笔记
    leetcode 162. 寻找峰值(二分)
    python matplotlib包的安装注意事项:报错——No such file or dir : tmp/matplotlib-xxxxxx
  • 原文地址:https://www.cnblogs.com/0to9/p/5151810.html
Copyright © 2020-2023  润新知