⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smartsoft.common.sql.dbfactory.cs

📁 一个通用的数据库操作类,可以访问ACESS,SQLServer,Oracle,OleDB等,并提供常用对表的读取及更新操作。
💻 CS
📖 第 1 页 / 共 5 页
字号:
using System;
using System.Xml;
using Microsoft.Win32;
using Microsoft.CSharp;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.OracleClient;
using System.Data.ProviderBase;
using System.Data.OleDb;
using System.Data.Odbc;
using System.Data.SqlTypes;
using System.Data.Sql;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Net;
using System.Media;
using System.Threading;
using System.Web;
using System.Windows;
using System.Windows.Forms;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Runtime.InteropServices;



namespace SmartSoft.Common.SQL.DBFactory
{


    #region  数据库类型String
    //System.Data.SqlClient
    //System.Data.Odbc
    //System.Data.OleDb
    //System.Data.OracleClient

    #endregion  数据库类型String

    public abstract class DBFactory数据库基础类
    {
        #region  数据库类型名称String
        //System.Data.SqlClient
        //System.Data.Odbc
        //System.Data.OleDb
        //System.Data.OracleClient

        #endregion  数据库类型名称String

        protected SmartSoft.Common.SQL.数据库类型 数据库类型enum = SmartSoft.Common.SQL.数据库类型.UnKnow;
        protected bool 操作正确否Bool = false;
        protected string 操作消息String = "";
        protected string 操作命令String = "";
        protected string 数据库链接字符串String = "";

        //------------------
        #region 构造函数
        public DBFactory数据库基础类(SmartSoft.Common.SQL.数据库类型 数据库类型enum, string 数据库链接字符串String)
        {
            this.数据库类型enum = 数据库类型enum;
            this.数据库链接字符串String = 数据库链接字符串String;

            this.数据库是否链接();
        }
        //-------------
        #endregion 构造函数
        //------------
        public bool 操作正确否
        {
            get
            {
                return this.操作正确否Bool;
            }
        }

        public string 数据库类型名称
        {
            get
            {
                return SmartSoft.Common.SQL.SQLExpression.数据库函数.数据库类型名称(this.数据库类型enum);
            }
        }

        public SmartSoft.Common.SQL.数据库类型 数据库类型
        {
            get
            {
                return this.数据库类型enum;
            }
        }

        public string 操作消息
        {
            get
            {
                return this.操作消息String;
            }
        }

        public string 数据库链接字符串
        {
            get
            {
                return this.数据库链接字符串String;
            }
        }

        public string 操作命令
        {
            get
            {
                return this.操作命令String;
            }
        }

        //--------------
        public bool 数据库是否链接()
        {
            this.操作命令String = "数据库链接";
            bool 数据库是否链接IsOk = false;
            try
            {
                数据库是否链接IsOk = SmartSoft.Common.SQL.DBFactory.数据库链接.数据库链接是否正确(this.数据库类型名称, this.数据库链接字符串);
                if (数据库是否链接IsOk)
                {
                    数据库是否链接IsOk = true;
                    this.操作成功();
                }
                else
                {
                    数据库是否链接IsOk = false;
                    this.操作失败();
                }
            }
            catch (Exception e)
            {
                数据库是否链接IsOk = false;
                this.操作失败(e);
            }
            return 数据库是否链接IsOk;
        }

        protected void 操作失败(Exception e)
        {
            this.操作失败();
            this.操作消息String = this.操作消息 + ";" + e.Message.ToString().Trim() + ";" + e.Source + e.StackTrace + ";" + e.TargetSite + ";";

        }

        protected void 操作失败()
        {
            this.操作正确否Bool = false;
            this.操作消息String = this.数据库类型.ToString() + " " + this.数据库类型名称 + " " + this.操作命令 + "失败 !";

        }

        protected void 操作成功()
        {
            this.操作正确否Bool = true;
            this.操作消息String = this.数据库类型.ToString() + " " + this.数据库类型名称 + " " + this.操作命令 + "成功 !";
        }

        #region 创建命令

        protected System.Data.IDbConnection 创建数据库链接Connection(string 数据库类型名称String, string 数据库链接字符串String)
        {
            System.Data.IDbConnection 数据库链接ConnectionX = null;
            this.操作命令String = "创建数据库链接";
            try
            {
                数据库链接ConnectionX = SmartSoft.Common.SQL.DBFactory.数据库链接.创建数据库链接Connection(数据库类型名称String, 数据库链接字符串String);
                this.操作成功();
            }
            catch (Exception e)
            {
                this.操作失败(e);
            }
            return 数据库链接ConnectionX;
        }
        #endregion 创建命令

        #region 基础命令
        //-----------------------
        protected string 数据库实例()
        {
            string 数据库实例String = "";
            数据库实例String = SmartSoft.Common.SQL.DBFactory.数据库链接.数据库实例(this.数据库类型名称, this.数据库链接字符串);
            return 数据库实例String;
        }

        protected string 数据库名称()
        {
            string 数据库名称String = "";
            数据库名称String = SmartSoft.Common.SQL.DBFactory.数据库链接.数据库名称(this.数据库类型名称, this.数据库链接字符串);
            return 数据库名称String;
        }
        //------------------------
        #endregion 基础命令


        #region 创建命令
        protected System.Data.IDbCommand 创建数据库命令Command(string 数据库类型名称String, string 数据库链接字符串String, CommandType 数据库命令类型CommandType, string 数据库命令文本CommandText, System.Data.IDbDataParameter[] 数据库命令参数CommandParameters)
        {
            System.Data.IDbCommand 数据库命令CommandX = null;
            this.操作命令String = "创建数据库命令";
            try
            {
                数据库命令CommandX = SmartSoft.Common.SQL.DBFactory.数据库命令.创建数据库命令Command(数据库类型名称String, 数据库链接字符串String, 数据库命令类型CommandType, 数据库命令文本CommandText, 数据库命令参数CommandParameters);
                this.操作成功();
            }
            catch (Exception e)
            {
                this.操作失败(e);
            }
            return 数据库命令CommandX;
        }

        protected System.Data.IDbCommand 创建无链接数据库命令Command(string 数据库类型名称String, CommandType 数据库命令类型CommandType, string 数据库命令文本CommandText, System.Data.IDbDataParameter[] 数据库命令参数CommandParameters)
        {
            System.Data.IDbCommand 数据库命令CommandX = null;
            this.操作命令String = "创建无链接数据库命令";
            try
            {
                数据库命令CommandX = SmartSoft.Common.SQL.DBFactory.数据库命令.创建无链接数据库命令Command(数据库类型名称String, 数据库命令类型CommandType, 数据库命令文本CommandText, 数据库命令参数CommandParameters);
                this.操作成功();
            }
            catch (Exception e)
            {
                this.操作失败(e);
            }
            return 数据库命令CommandX;
        }

        #endregion 创建命令

        #region 基础命令
       
        protected int 数据库命令非查询(CommandType 数据库命令类型CommandType, string 数据库命令文本CommandText, params IDbDataParameter[] 数据库命令参数CommandParameters)
        {
            this.操作命令String = "数据库命令非查询";
            int 非查询操作返回值Int = 0;
            try
            {
                非查询操作返回值Int = SmartSoft.Common.SQL.DBFactory.数据库命令.数据库命令非查询(this.数据库类型名称, this.数据库链接字符串, 数据库命令类型CommandType, 数据库命令文本CommandText, 数据库命令参数CommandParameters);
                this.操作成功();
            }
            catch (Exception e)
            {
                this.操作失败(e);
            }
            return 非查询操作返回值Int;
        }

        public bool 数据库命令事务非查询(params System.Data.IDbCommand[] 数据库命令Commands)
        {
            bool 非查询操作IsOK = false;
            this.操作命令String = "数据库命令事务非查询";
            try
            {
                if (数据库命令Commands != null)
                {
                    非查询操作IsOK = SmartSoft.Common.SQL.DBFactory.数据库命令.数据库命令事务非查询(this.数据库类型名称, this.数据库链接字符串, 数据库命令Commands);
                    if (非查询操作IsOK)
                    {
                        this.操作成功();
                    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -