MySqlDBHelper

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;
using System.Collections;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using System.Configuration;
using System.IO;

namespace DALProfile
{
    public class MySqlDBHelper
    {
        //Get the database connectionstring, which are static variables and readonly, all project documents can be used directly, but can not modify it
        //the database connectionString
        public static string ConnectionStringManager
        {
            get { return connectionStringManager; }
        }

        //This connectionString for the local test
        public static readonly string connectionStringManager = System.Configuration.ConfigurationManager.ConnectionStrings["MySQLConnString"].ConnectionString;
        //ConfigurationManager.ConnectionStrings["MySQLConnString"].ConnectionString;

        //hashtable to store the parameter information, the hash table can store any type of argument
        //Here the hashtable is static types of static variables, since it is static, that is a definition of global use.
        //All parameters are using this hash table, how to ensure that others in the change does not affect their time to read it
        //Before ,the method can use the lock method to lock the table, does not allow others to modify.when it has readed then  unlocked table.
        //Now .NET provides a HashTable‘s Synchronized methods to achieve the same function, no need to manually lock, completed directly by the system framework
        private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());

        /// <summary>
        /// Execute a SqlCommand command that does not return value, by appointed and specified connectionstring
        /// The parameter list using parameters that in array forms
        /// </summary>
        /// <remarks>
        /// Usage example:
        /// int result = ExecuteNonQuery(connString, CommandType.StoredProcedure,
        /// "PublishOrders", new MySqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connectionString">a valid database connectionstring</param>
        /// <param name="cmdType">MySqlCommand command type (stored procedures, T-SQL statement, and so on.) </param>
        /// <param name="cmdText">stored procedure name or T-SQL statement</param>
        /// <param name="commandParameters">MySqlCommand to provide an array of parameters used in the list</param>
        /// <returns>Returns a value that means number of rows affected/returns>
        public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
        {
            MySqlCommand cmd = new MySqlCommand();

            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                int val = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                return val;
            }
        }

        /// <summary>
        /// Execute a SqlCommand command that does not return value, by appointed and specified connectionstring
        /// The parameter list using parameters that in array forms
        /// </summary>
        /// <remarks>
        /// Usage example:
        /// int result = ExecuteNonQuery(connString, CommandType.StoredProcedure,
        /// "PublishOrders", new MySqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="cmdType">MySqlCommand command type (stored procedures, T-SQL statement, and so on.) </param>
        /// <param name="connectionString">a valid database connectionstring</param>
        /// <param name="cmdText">stored procedure name or T-SQL statement</param>
        /// <param name="commandParameters">MySqlCommand to provide an array of parameters used in the list</param>
        /// <returns>Returns true or false </returns>
        public static bool ExecuteNonQuery(CommandType cmdType, string connectionString, string cmdText, params MySqlParameter[] commandParameters)
        {
            MySqlCommand cmd = new MySqlCommand();

            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                try
                {
                    int val = cmd.ExecuteNonQuery();
                    return true;
                }
                catch
                {
                    return false;
                }
                finally
                {
                    cmd.Parameters.Clear();
                }
            }
        }
        /// <summary>
        /// Execute a SqlCommand command that does not return value, by appointed and specified connectionstring
        /// Array of form parameters using the parameter list
        /// </summary>
        /// <param name="conn">connection</param>
        /// <param name="cmdType">MySqlCommand command type (stored procedures, T-SQL statement, and so on.)</param>
        /// <param name="cmdText">stored procedure name or T-SQL statement</param>
        /// <param name="commandParameters">MySqlCommand to provide an array of parameters used in the list</param>
        /// <returns>Returns a value that means number of rows affected</returns>
        public static int ExecuteNonQuery(MySqlConnection conn, CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
        {
            MySqlCommand cmd = new MySqlCommand();
            PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
            int val = cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
            return val;
        }

        /// <summary>
        /// Execute a SqlCommand command that does not return value, by appointed and specified connectionstring
        /// Array of form parameters using the parameter list
        /// </summary>
        /// <param name="conn">sql Connection that has transaction</param>
        /// <param name="cmdType">SqlCommand command type (stored procedures, T-SQL statement, and so on.)</param>
        /// <param name="cmdText">stored procedure name or T-SQL statement</param>
        /// <param name="commandParameters">MySqlCommand to provide an array of parameters used in the list</param>
        /// <returns>Returns a value that means number of rows affected </returns>
        public static int ExecuteNonQuery(MySqlTransaction trans, CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
        {
            MySqlCommand cmd = new MySqlCommand();
            PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
            int val = cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
            return val;
        }

        /// <summary>
        /// Call method of sqldatareader to read data
        /// </summary>
        /// <param name="connectionString">connectionstring</param>
        /// <param name="cmdType">command type, such as using stored procedures: CommandType.StoredProcedure</param>
        /// <param name="cmdText">stored procedure name or T-SQL statement</param>
        /// <param name="commandParameters">parameters</param>
        /// <returns>SqlDataReader type of data collection</returns>
        public static MySqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
        {
            MySqlCommand cmd = new MySqlCommand();
            MySqlConnection conn = new MySqlConnection(connectionString);

            // we use a try/catch here because if the method throws an exception we want to
            // close the connection throw code, because no datareader will exist, hence the
            // commandBehaviour.CloseConnection will not work
            try
            {
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                MySqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                cmd.Parameters.Clear();
                return rdr;
            }
            catch
            {
                conn.Close();
                throw;
            }
        }

        /// <summary>
        /// use the ExectueScalar to read a single result
        /// </summary>
        /// <param name="connectionString">connectionstring</param>
        /// <param name="cmdType">command type, such as using stored procedures: CommandType.StoredProcedure</param>
        /// <param name="cmdText">stored procedure name or T-SQL statement</param>
        /// <param name="commandParameters">parameters</param>
        /// <returns>a value in object type</returns>
        public static object ExecuteScalar(string connectionString, CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
        {
            MySqlCommand cmd = new MySqlCommand();

            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
                object val = cmd.ExecuteScalar();
                cmd.Parameters.Clear();
                return val;
            }
        }
        public static DataTable ExecuteDataTable(string connectionString, string cmdText, params MySqlParameter[] commandParameters)
        {
            DataSet retSet = new DataSet();
            using (MySqlDataAdapter msda = new MySqlDataAdapter(cmdText, connectionString))
            {
                msda.Fill(retSet);
            }
            if (retSet != null && retSet.Tables.Count > 0)
            {
                return retSet.Tables[0];
            }
            return null;
        }
        public static DataTable ExecuteDataTable(string connectionString, CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
        {
            DataSet retSet = new DataSet();
            MySqlCommand cmd = new MySqlCommand();
            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
                using (MySqlDataAdapter msda = new MySqlDataAdapter(cmd))
                {
                    msda.Fill(retSet);
                }
            }
            if (retSet != null && retSet.Tables.Count > 0)
            {
                return retSet.Tables[0];
            }
            return null;
        }
        public static DataSet GetDataSet(string connectionString, string cmdText, params MySqlParameter[] commandParameters)
        {
            DataSet retSet = new DataSet();
            using (MySqlDataAdapter msda = new MySqlDataAdapter(cmdText, connectionString))
            {
                msda.Fill(retSet);
            }
            return retSet;
        }

        /// <summary>
        /// cache the parameters in the HashTable
        /// </summary>
        /// <param name="cacheKey">hashtable key name</param>
        /// <param name="commandParameters">the parameters that need to cached</param>
        public static void CacheParameters(string cacheKey, params MySqlParameter[] commandParameters)
        {
            parmCache[cacheKey] = commandParameters;
        }

        /// <summary>
        /// get parameters in hashtable by cacheKey
        /// </summary>
        /// <param name="cacheKey">hashtable key name</param>
        /// <returns>the parameters</returns>
        public static MySqlParameter[] GetCachedParameters(string cacheKey)
        {
            MySqlParameter[] cachedParms = (MySqlParameter[])parmCache[cacheKey];

            if (cachedParms == null)
                return null;

            MySqlParameter[] clonedParms = new MySqlParameter[cachedParms.Length];

            for (int i = 0, j = cachedParms.Length; i < j; i++)
                clonedParms[i] = (MySqlParameter)((ICloneable)cachedParms[i]).Clone();

            return clonedParms;
        }

        /// <summary>
        ///Prepare parameters for the implementation of the command
        /// </summary>
        /// <param name="cmd">mySqlCommand command</param>
        /// <param name="conn">database connection that is existing</param>
        /// <param name="trans">database transaction processing </param>
        /// <param name="cmdType">SqlCommand command type (stored procedures, T-SQL statement, and so on.) </param>
        /// <param name="cmdText">Command text, T-SQL statements such as Select * from Products</param>
        /// <param name="cmdParms">return the command that has parameters</param>
        private static void PrepareCommand(MySqlCommand cmd, MySqlConnection conn, MySqlTransaction trans, CommandType cmdType, string cmdText, MySqlParameter[] cmdParms)
        {
            if (conn.State != ConnectionState.Open)
                conn.Open();

            cmd.Connection = conn;
            cmd.CommandText = cmdText;

            if (trans != null)
                cmd.Transaction = trans;

            cmd.CommandType = cmdType;

            if (cmdParms != null)
                foreach (MySqlParameter parm in cmdParms)
                    cmd.Parameters.Add(parm);
        }
        #region parameters
        /// <summary>
        /// Set parameters
        /// </summary>
        /// <param name="ParamName">parameter name</param>
        /// <param name="DbType">data type</param>
        /// <param name="Size">type size</param>
        /// <param name="Direction">input or output</param>
        /// <param name="Value">set the value</param>
        /// <returns>Return parameters that has been assigned</returns>
        public static MySqlParameter CreateParam(string ParamName, MySqlDbType DbType, Int32 Size, ParameterDirection Direction, object Value)
        {
            MySqlParameter param;

            if (Size > 0)
            {
                param = new MySqlParameter(ParamName, DbType, Size);
            }
            else
            {

                param = new MySqlParameter(ParamName, DbType);
            }

            param.Direction = Direction;
            if (!(Direction == ParameterDirection.Output && Value == null))
            {
                param.Value = Value;
            }

            return param;
        }

        /// <summary>
        /// set Input parameters
        /// </summary>
        /// <param name="ParamName">parameter names, such as:@ id </param>
        /// <param name="DbType">parameter types, such as: MySqlDbType.Int</param>
        /// <param name="Size">size parameters, such as: the length of character type for the 100</param>
        /// <param name="Value">parameter value to be assigned</param>
        /// <returns>Parameters</returns>
        public static MySqlParameter CreateInParam(string ParamName, MySqlDbType DbType, int Size, object Value)
        {
            return CreateParam(ParamName, DbType, Size, ParameterDirection.Input, Value);
        }

        /// <summary>
        /// Output parameters
        /// </summary>
        /// <param name="ParamName">parameter names, such as:@ id</param>
        /// <param name="DbType">parameter types, such as: MySqlDbType.Int</param>
        /// <param name="Size">size parameters, such as: the length of character type for the 100</param>
        /// <param name="Value">parameter value to be assigned</param>
        /// <returns>Parameters</returns>
        public static MySqlParameter CreateOutParam(string ParamName, MySqlDbType DbType, int Size)
        {
            return CreateParam(ParamName, DbType, Size, ParameterDirection.Output, null);
        }

        /// <summary>
        /// Set return parameter value
        /// </summary>
        /// <param name="ParamName">parameter names, such as:@ id</param>
        /// <param name="DbType">parameter types, such as: MySqlDbType.Int</param>
        /// <param name="Size">size parameters, such as: the length of character type for the 100</param>
        /// <param name="Value">parameter value to be assigned<</param>
        /// <returns>Parameters</returns>
        public static MySqlParameter CreateReturnParam(string ParamName, MySqlDbType DbType, int Size)
        {
            return CreateParam(ParamName, DbType, Size, ParameterDirection.ReturnValue, null);
        }

        /// <summary>
        /// Generate paging storedProcedure parameters
        /// </summary>
        /// <param name="CurrentIndex">CurrentPageIndex</param>
        /// <param name="PageSize">pageSize</param>
        /// <param name="WhereSql">query Condition</param>
        /// <param name="TableName">tableName</param>
        /// <param name="Columns">columns to query</param>
        /// <param name="Sort">sort</param>
        /// <returns>MySqlParameter collection</returns>
        public static MySqlParameter[] GetPageParm(int CurrentIndex, int PageSize, string WhereSql, string TableName, string Columns, Hashtable Sort)
        {
            MySqlParameter[] parm = {
                                   MySqlDBHelper.CreateInParam("@CurrentIndex",  MySqlDbType.Int32,      4,      CurrentIndex    ),
                                   MySqlDBHelper.CreateInParam("@PageSize",      MySqlDbType.Int32,      4,      PageSize        ),
                                   MySqlDBHelper.CreateInParam("@WhereSql",      MySqlDbType.VarChar,  2500,    WhereSql        ),
                                   MySqlDBHelper.CreateInParam("@TableName",     MySqlDbType.VarChar,  20,     TableName       ),
                                   MySqlDBHelper.CreateInParam("@Column",        MySqlDbType.VarChar,  2500,    Columns         ),
                                   MySqlDBHelper.CreateInParam("@Sort",          MySqlDbType.VarChar,  50,     GetSort(Sort)   ),
                                   MySqlDBHelper.CreateOutParam("@RecordCount",  MySqlDbType.Int32,      4                       )
                                   };
            return parm;
        }
        /// <summary>
        /// Statistics data that in table
        /// </summary>
        /// <param name="TableName">table name</param>
        /// <param name="Columns">Statistics column</param>
        /// <param name="WhereSql">conditions</param>
        /// <returns>Set of parameters</returns>
        public static MySqlParameter[] GetCountParm(string TableName, string Columns, string WhereSql)
        {
            MySqlParameter[] parm = {
                                   MySqlDBHelper.CreateInParam("@TableName",     MySqlDbType.VarChar,  20,     TableName       ),
                                   MySqlDBHelper.CreateInParam("@CountColumn",  MySqlDbType.VarChar,  20,     Columns         ),
                                   MySqlDBHelper.CreateInParam("@WhereSql",      MySqlDbType.VarChar,  250,    WhereSql        ),
                                   MySqlDBHelper.CreateOutParam("@RecordCount",  MySqlDbType.Int32,      4                       )
                                   };
            return parm;
        }
        /// <summary>
        /// Get the sql that is Sorted
        /// </summary>
        /// <param name="sort"> sort column and values</param>
        /// <returns>SQL sort string</returns>
        private static string GetSort(Hashtable sort)
        {
            string str = "";
            int i = 0;
            if (sort != null && sort.Count > 0)
            {
                foreach (DictionaryEntry de in sort)
                {
                    i++;
                    str += de.Key + " " + de.Value;
                    if (i != sort.Count)
                    {
                        str += ",";
                    }
                }
            }
            return str;
        }

        /// <summary>
        /// execute a trascation include one or more sql sentence(author:donne yin)
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="cmdType"></param>
        /// <param name="cmdTexts"></param>
        /// <param name="commandParameters"></param>
        /// <returns>execute trascation result(success: true | fail: false)</returns>
        public static bool ExecuteTransaction(string connectionString, CommandType cmdType, string[] cmdTexts, params MySqlParameter[][] commandParameters)
        {
            MySqlConnection myConnection = new MySqlConnection(connectionString);       //get the connection object
            myConnection.Open();                                                        //open the connection
            MySqlTransaction myTrans = myConnection.BeginTransaction();                 //begin a trascation
            MySqlCommand cmd = new MySqlCommand();
            cmd.Connection = myConnection;
            cmd.Transaction = myTrans;

            try
            {
                for (int i = 0; i < cmdTexts.Length; i++)
                {
                    PrepareCommand(cmd, myConnection, null, cmdType, cmdTexts[i], commandParameters[i]);
                    cmd.ExecuteNonQuery();
                    cmd.Parameters.Clear();
                }
                myTrans.Commit();
            }
            catch
            {
                myTrans.Rollback();
                return false;
            }
            finally
            {
                myConnection.Close();
            }
            return true;
        }
        #endregion

        /// <summary>
        /// 分页获得数据
        /// </summary>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">每页显示数据量</param>
        /// <param name="TableName">表名,可以是自定义查询集合</param>
        /// <param name="_Where">条件语句,需要以where开头</param>
        /// <param name="OrderStr">排序语句</param>
        /// <param name="RecordCount">记录数 输出参数</param>
        /// <param name="PageCount">总页数 输出参数</param>
        /// <returns></returns>
        public static DataTable GetDataTableByPage(string connectionString, int PageIndex, int PageSize, string TableName, string _Where, string OrderStr, out int RecordCount, out int PageCount)
        {
            string selectText = @"SELECT * FROM " + TableName + " " + _Where + " " + OrderStr + " LIMIT " + ((PageIndex - 1) * PageSize).ToString() + "," + PageSize.ToString();
            string countText = @"SELECT count(*) FROM " + TableName + " " + _Where;

            DataSet retSet = new DataSet();
            using (MySqlDataAdapter msda = new MySqlDataAdapter(selectText, connectionString))
            {
                msda.Fill(retSet);
            }
            object objCount = ExecuteScalar(connectionString, CommandType.Text, countText, null);

            RecordCount = 0;
            PageCount = 1;
            if (objCount != null && objCount != DBNull.Value)
            {
                RecordCount = Convert.ToInt32(objCount);
                PageCount = (RecordCount / PageSize) + ((RecordCount % PageSize) > 0 ? 1 : 0);
            }
            if (retSet != null && retSet.Tables.Count > 0)
            {
                return retSet.Tables[0];
            }
            return null;
        }
        /// <summary>
        /// 分页获得数据
        /// </summary>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">每页显示数据量</param>
        /// <param name="TableName">表名,可以是自定义查询集合</param>
        /// <param name="Fields">字段名</param>
        /// <param name="_Where">条件语句,需要以where开头</param>
        /// <param name="OrderStr">排序语句</param>
        /// <param name="RecordCount">记录数 输出参数</param>
        /// <param name="PageCount">总页数 输出参数</param>
        /// <returns></returns>
        public static DataTable GetDataTableByPage(string connectionString, int PageIndex, int PageSize, string TableName, string Fields, string _Where, string OrderStr, out int RecordCount, out int PageCount)
        {
            string selectText = @"SELECT " + Fields + " FROM " + TableName + " " + _Where + " " + OrderStr + " LIMIT " + ((PageIndex - 1) * PageSize).ToString() + "," + PageSize.ToString();
            string countText = @"SELECT COUNT(*) FROM " + TableName + " " + _Where;

            DataSet retSet = new DataSet();
            using (MySqlDataAdapter msda = new MySqlDataAdapter(selectText, connectionString))
            {
                msda.Fill(retSet);
            }
            object objCount = ExecuteScalar(connectionString, CommandType.Text, countText, null);

            RecordCount = 0;
            PageCount = 1;
            if (objCount != null && objCount != DBNull.Value)
            {
                RecordCount = Convert.ToInt32(objCount);
                PageCount = (RecordCount / PageSize) + ((RecordCount % PageSize) > 0 ? 1 : 0);
            }
            if (retSet != null && retSet.Tables.Count > 0)
            {
                return retSet.Tables[0];
            }
            return null;
        }
    }
}

需要下载一个MySql.Data.dll文件

下载地址:http://pan.baidu.com/s/1b9f2Qq

连接字符串格式:<add name="MySQLConnString" connectionString="server=******; user id=******j; password=******; database=******"/>

注意:connectionString 不是 Data Source了,是server。

时间: 2024-11-07 07:53:21

MySqlDBHelper的相关文章

善用设计模式改善我们丑陋的代码——策略模式

有时候因为种种原因导致我们会写出很多丑陋的代码,比如赶工时,短暂性的偷懒,不会设计模式等等导致代码沉积,一个cs上万行代码这样场景是有发生, 当然这里也包括我...所以时间充裕一点之后就想重构一下,毕竟项目中的需求是不断变更的,面对需求变更,尽量做到最低限度的修改代码,最大化的扩充 新代码,还有一点就是不要过分的追求设计模式,做到适可为止,太设计模式了会导致类太多,不好管理,在项目开发中,其实仔细考虑一下,你会发现很多业 务逻辑都有相应的设计模式帮你优化,毕竟这些都是前辈们踩了无数的坑,经过无数

返回值为DataTable的数据,在MVC视图里的用法

控制器里的代码如下: private MySqlDbHelper msh = new MySqlDbHelper();        public ActionResult Index()        {            string sql = "select * from deviceType";            DataTable dt = msh.GetDataTable(sql, null);            return View(dt);       

闲来无事,编写一个数据迁移小工具

一.前言 生命不息,折腾不止.近期公司有数据迁移的计划,从Sqlserver迁移到mysql,虽说网上有很多数据迁移方案,但闲着也是闲着,就自己整一个,权当做是练练手了 二.解决思路 整个迁移过程类似于ETL,将数据从来源端经过抽取(extract).转换(transform).加载(load)至目的端.读取并转换sqlserver库数据,将数据解析为csv文件,载入文件到mysql.流程如下: 抽取.转换此过程主要是处理源数据库与目标数据库表字段的映射关系,为了保证程序的通用性,通过配置文件映

利用通用权限管理系统底层解决数据从不同库的导入导出问题

/// <summary> /// 同步地区的处理 /// Base_Area表从Oracle同步到MySQL数据库 /// </summary> /// <returns></returns> public ActionResult SyncAreaFromOracleToMySql() { BaseResult baseResult = new BaseResult(); string currentId = string.Empty; try { Ba

Android数据存储之SQLite

SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,占用资源非常少,只有几百KB内存.支持Windows/Linux/Unix等等主流的操作系统,同时能够跟其他程序语言相结合,比如 Tcl.C#.PHP.Java等,还有ODBC接口,同样比起Mysql.PostgreSQL这两款开源的世界著名数据库管理系统来讲,它的处理速度比他们都快.SQLite是当前使用最广泛的数据库,基于以上优点,Android系统采用SQ

C# 各种帮助类大全

前言 此篇专门记录一些常见DB帮助类及其他帮助类,以便使用时不用重复造轮子. DBHelper帮助类 ①首当其冲的就是Sql Server帮助类,创建名为DbHelperSQL 的类 ,全部代码如下: /// <summary> /// 数据访问抽象基础类 /// Copyright (C) Maticsoft /// </summary> public abstract class DbHelperSQL { //数据库连接字符串(web.config来配置),多数据库可使用Db

T4模版 mysql

MysqlDbhelper.ttinclude ---------------------------------------------------------------------------->> <#@ assembly name="System.Core"#><#@ assembly name="System.Data"#><#@ assembly name="MySql.Data"#>

MySQL数据库工具类之——DataTable批量加入MySQL数据库(Net版)

MySQL数据库工具类之——DataTable批量加入数据库(Net版),MySqlDbHelper通用类希望能对大家有用,代码如下: using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Text; p

配置文件通过读取json方式读取

json文件 { "mysql":{ "hosts":"localhost", "user":"root", "password":"admin", "port":3306, "dbname":"jfg", "chart":"utf-8" }, "redis&