欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Access2007数据库下载地址与AccessHelper

程序员文章站 2022-07-11 11:18:55
链接:https://pan.baidu.com/s/1pLzOlTv0nqSbhzujHZht1w 提取码:1m9l AccessHelper: //Microsoft.ACE.OLEDB.12.0是连接access2007之后的数据库使用的 //Microsoft.Jet.OLEDB.4.0是连 ......

链接:https://pan.baidu.com/s/1plzoltv0nqsbhzujhzht1w 
提取码:1m9l 

accesshelper:

using system;
using system.collections.generic;
using system.data;
using system.data.oledb;
using system.linq;
using system.text;

namespace accessireaderdemo
{
    public class accesshelper
    {
        string str = @"provider=microsoft.jet.oledb.4.0; data source=f:\邯钢工作计划\物理站\华龙冲击\cbddata2018.mdb";
        private static string str;

        public accesshelper(string _connstr)
        {
            str = _connstr;
        }
        public static dataset excedataset(string sql, oledbparameter[] parm = null,
            commandtype type = commandtype.text)
        {
            using (oledbconnection conn = new oledbconnection(str))
            {
                using (oledbcommand cmd = new oledbcommand(sql, conn))
                {
                    if (parm != null)
                        cmd.parameters.addrange(parm);
                    oledbdataadapter abs = new oledbdataadapter(cmd);
                    dataset set = new dataset();
                    conn.open();
                    abs.fill(set);
                    return set;
                }
            }
        }

        /// <summary>
        /// reader
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parm"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static oledbdatareader reader(string sql, oledbparameter[] parm = null,
            commandtype type = commandtype.text)
        {
            oledbconnection conn = new oledbconnection(str);
            oledbcommand cmd = new oledbcommand(sql, conn);
            if (parm != null)
                cmd.parameters.addrange(parm);
            conn.open();
            oledbdatareader reader = null;
            try
            {
                reader = cmd.executereader(commandbehavior.closeconnection);

            }
            catch (exception e)
            {

                throw;
            }
            return reader;
        }

        /// <summary>
        /// 查询首行首列
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parm"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static object excescale(string sql, oledbparameter[] parm = null, commandtype type = commandtype.text)
        {
            using (oledbconnection conn = new oledbconnection(str))
            {
                using (oledbcommand cmd = new oledbcommand(sql, conn))
                {
                    if (parm != null)
                        cmd.parameters.addrange(parm);
                    cmd.commandtype = type;
                    conn.open();
                    return cmd.executescalar();

                }
            }
        }

        /// <summary>
        /// 几行受影响
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parm"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static int excequery(string sql, oledbparameter[] parm = null, commandtype type = commandtype.text)
        {
            using (oledbconnection conn = new oledbconnection(str))
            {
                using (oledbcommand cmd = new oledbcommand(sql, conn))
                {
                    if (parm != null)
                        cmd.parameters.addrange(parm);
                    cmd.commandtype = type;
                    conn.open();
                    return cmd.executenonquery();
                }
            }
        }

    }
}

//microsoft.ace.oledb.12.0是连接access2007之后的数据库使用的
//microsoft.jet.oledb.4.0是连接access2003等数据库使用的。