using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;//导命名空间

using System.Data;

using MySql.Data.MySqlClient;

using System.Configuration;

namespace Test.DAL.MySql

{

public class DBHelp { private readonly string connString = ConfigurationManager.ConnectionStrings["mysql"].ToString(); private MySqlConnection mySqlConnection = null; private MySqlCommand mySqlCommand = null; protected MySqlDataReader mySqlDataReader = null; private MySqlDataAdapter mySqlDataAdapter = null; private DataSet dataSet = null; private int i = 0; private MySqlConnection ExecuteMySqlConnection() { try { this.mySqlConnection = new MySqlConnection(this.connString); this.mySqlConnection.Open(); } catch (Exception) { throw; } return this.mySqlConnection; } private MySqlCommand ExecuteMySqlCommand(string sql,CommandType commandType,MySqlParameter[] mySqlParameter) { try { this.mySqlConnection = this.ExecuteMySqlConnection(); this.mySqlCommand = new MySqlCommand(sql, this.mySqlConnection); if (mySqlParameter != null && mySqlParameter.Length > 0) { this.mySqlCommand.Parameters.AddRange(mySqlParameter); } this.mySqlCommand.CommandType = commandType; } catch (Exception) { throw; } return this.mySqlCommand; } protected MySqlDataReader ExecuteMySqlDataReader(string sql, CommandType commandType, MySqlParameter[] mySqlParameter) { try { this.mySqlCommand = this.ExecuteMySqlCommand(sql, commandType, mySqlParameter); this.mySqlDataReader = this.mySqlCommand.ExecuteReader(); } catch (Exception) { throw; } return this.mySqlDataReader; } protected DataSet ExecuteDataSet(string sql, CommandType commandType, MySqlParameter[] mySqlParameter) { this.dataSet = new DataSet(); try { this.mySqlCommand = this.ExecuteMySqlCommand(sql, commandType, mySqlParameter); this.mySqlDataAdapter = new MySqlDataAdapter(this.mySqlCommand); this.mySqlDataAdapter.Fill(dataSet); } catch (Exception) { throw; } return this.dataSet; } protected int ExecuteScalar(string sql, CommandType commandType, MySqlParameter[] mySqlParameter) { try { this.mySqlCommand = this.ExecuteMySqlCommand(sql, commandType, mySqlParameter); this.i = int.Parse(this.mySqlCommand.ExecuteScalar().ToString()); } catch (Exception) { throw; } return this.i; } protected int ExecuteNonQuery(string sql, CommandType commandType, MySqlParameter[] mySqlParameter) { try { this.mySqlCommand = this.ExecuteMySqlCommand(sql, commandType, mySqlParameter); this.i = this.mySqlCommand.ExecuteNonQuery(); } catch (Exception) { throw; } return this.i; } protected void CloseConnection(MySqlConnection mySqlConnection) { try { if (mySqlConnection != null) { mySqlConnection = null; mySqlConnection.Close(); } } catch (Exception) { throw; } } protected void CloseDataReader(MySqlDataReader mySqlDataReader) { try { if (mySqlDataReader != null) { mySqlDataReader = null; mySqlDataReader.Close(); } } catch (Exception) { throw; } } }

}

MySql c#通用类的更多相关文章

  1. MySql c#通用类 转

    using System;using System.Data;using System.Configuration;using System.Collections.Generic;using Sys ...

  2. C#---数据库访问通用类、Access数据库操作类、mysql类 .[转]

    原文链接 //C# 数据库访问通用类 (ADO.NET)using System;using System.Collections.Generic;using System.Text;using Sy ...

  3. C#---数据库访问通用类、Access数据库操作类、mysql类 .

    //C# 数据库访问通用类 (ADO.NET)using System;using System.Collections.Generic;using System.Text;using System. ...

  4. C#操作SqlServer MySql Oracle通用帮助类

    C#操作SqlServer MySql Oracle通用帮助类 [前言] 作为一款成熟的面向对象高级编程语言,C#在ADO.Net的支持上已然是做的很成熟,我们可以方便地调用ADO.Net操作各类关系 ...

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

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

  6. SpringBoot 2.0 mybatis mapper通用类

    <!---mybatis通用类包含mybatis和连接池 mybatis和连接池就不需要引入--> <dependency> <groupId>tk.mybatis ...

  7. (一 、上)搭建简单的SpringBoot + java + maven + mysql + Mybatis+通用Mapper 《附项目源码》

    最近公司一直使用 springBoot 作为后端项目框架, 也负责搭建了几个新项目的后端框架.在使用了一段时间springBoot 后,感觉写代码 比spring 更加简洁了(是非常简洁),整合工具也 ...

  8. 第一天:java与mysql的连接工具类

    第一天:java与mysql的连接工具类 java最新版马上就要收费,这无疑是这门语言的衰败起始,毕竟在中国收费便难发展,例如c#,但是毕业设计已经选好用java来写一个动态网站, 这已经是一个事实, ...

  9. springboot学习笔记:8. springboot+druid+mysql+mybatis+通用mapper+pagehelper+mybatis-generator+freemarker+layui

    前言: 开发环境:IDEA+jdk1.8+windows10 目标:使用springboot整合druid数据源+mysql+mybatis+通用mapper插件+pagehelper插件+mybat ...

随机推荐

  1. iOS 中plist文件中配置key值冲突的现象

    iOS开发一些特殊的软件需要在项目中配置对应的key值,然而近期在项目中发现一个有意思的现象,苹果官方文档中提供的key值很多,但其实有一些彼此可能有冲突,当你同时配置了彼此冲突的key值,可能会出现 ...

  2. jquery制作动态添加表单行与删除表单行

    <script type="text/javascript" src="js/jquery1.7.js"></script> <s ...

  3. $(document).ready(function(){}) 与 window.onload = function(){} 区别

    $(document).ready(fucntion(){ //在页面dom结构加载完毕后执行代码, }) window.onload = function(){ //页面所有内容加载完毕后,执行代码 ...

  4. G. I love Codeforces

    G. I love Codeforces 题目大意:给你n个字符串,以及m个喜欢关系,如果u喜欢v,这时候u会把它的用户名改为 I_love_ 加上v当时的用户名 Examples input 5an ...

  5. Luogu P2970 [USACO09DEC]自私的放牧

    https://www.luogu.org/problemnew/show/P2970 P2970 [USACO09DEC]自私的放牧 题目描述 Each of Farmer John's N (1 ...

  6. 小白神器 - 一篇博客学会HTML

    小白神器 - 一篇博客学会HTML 一. 简介 1. HTML 定义 htyper text markup language  即超文本标记语言. 超文本: 就是指页面内可以包含图片.链接,甚至音乐. ...

  7. NLTK学习笔记(七):文本信息提取

    目录 实体识别:分块技术 分块语法的构建 树状图 IOB标记 开发和评估分块器 命名实体识别和信息提取 如何构建一个系统,用于从非结构化的文本中提取结构化的信息和数据?哪些方法使用这类行为?哪些语料库 ...

  8. Ubuntu_linux系统与网络服务管理

    1.远程telnet联机:telnetd: 2.远程加密ssh联机:openssh: 3.webmin远程联机:webmin: 3.VNC远程图像界面控制:vino: 4.NAT网关服务器:iptab ...

  9. 233 Matrix 矩阵快速幂

    In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...

  10. 修改 db_unique_name

    在创建DB的时候 db_unique_name设置错了.本来我是想让 db_name=itid db_unique_name=itid1 不过想改回来很简单的. SQL> alter syste ...