【经典】c#下各种数据库操作的封装!(支持ACCESS,SQLSERVER,DB2,ORACLE,MYSQL)

该博客分享了如何在C#中实现对多种数据库(ACCESS, SQLSERVER, DB2, ORACLE, MYSQL)的操作封装,包括连接初始化、打开、关闭、查询、非查询操作等基本功能,并提供了接口和工厂模式来创建不同类型的数据库访问对象。" 85799647,7971207,使用动态规划优化花店橱窗布置,"['动态规划', '算法', '问题解决', '数据结构']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

c#下各种数据库操作的封装!(支持ACCESS,SQLSERVER,DB2,ORACLE,MYSQL)

【转】http://hi.baidu.com/hou5757219/blog/item/ce34f51956998d73dab4bd95.html

 

public enum DBType
    ...{
        Access,
        SQL,
        DB2,
        Oracle,
        MySQL
    }

    public interface IDBAccess
    ...{
        void Init(string strServer, string strDataBase, string strUser, string strPwd);
        void Open();
        void Close();
        bool TestConn();
        int RunNoQuery(string strCmd);
        DataTable RunQuery(string strCmd);
        DBType DBType ...{ get;}
        int GetFiledMax(string strTable, string strField);
        DataTable Tables ...{ get; }
        DataTable GetColumns();
        DataTable GetColumns(string strTable);
    }

    public static class DBAccessFactory
    ...{
        public static IDBAccess Create(DBType type)
        ...{
            IDBAccess IRet = null;
            switch (type)
            ...{
                case DBType.Access:
                    IRet = new Access(type);
                    break;

                case DBType.SQL:
                    IRet = new SQL(type);
                    break;

                default:
                    break;
            }
            return IRet;
        }

        private abstract class DBAccess : IDBAccess
        ...{
            protected DbConnection m_oConn = null;
            protected const string CON_strServer = "Server";
            protected const string CON_strDataBase = "Data Source";
            protected const string CON_strUser = "UID";
            protected const string CON_strPwd = "PWD";
            protected const string CON_strConnTimeOut = "Connect Timeout = 2";
            private DBType m_eDBType = DBType.Access;

            protected DBAccess(DBType type)
            ...{
                this.m_eDBType = type;
            }

            public DBType DBType
            ...{
&nbs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值