当前位置: 移动技术网 > IT编程>开发语言>.net > Access2007数据库下载地址与AccessHelper

Access2007数据库下载地址与AccessHelper

2019年03月07日  | 移动技术网IT编程  | 我要评论

狼局长十八摸,周一上班的熊样gif,叶晓丽

链接: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等数据库使用的。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网