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. react 子组件给父组件传值

    import React from 'react'import '../page1/header.css'import { Table } from 'antd'import Child from ' ...

  2. Thawte

    Thawte 公司为 VeriSign(即:现更名为Symantec) 全资子公司,是全球第三大数字证书颁发机构(CA),成立于1995年,自1996年正式提供数字证书产品到1999年占领全球市场的4 ...

  3. 赛门铁克扩展验证EV SSL证书

      申请EV SSL证书,将接受最严格验证企业域名所有权和企业身份信息,属于最高信任级别扩展验证(EV)的 EV SSL证书,最高达256位自适应加密.Symantec不仅提供先进的SSL加密技术,同 ...

  4. [Bzoj3940] [AC自动机,USACO 2015 February Gold] Censor [AC自动机模板题]

    AC自动机模板题(膜jcvb代码) #include <iostream> #include <algorithm> #include <cstdio> #incl ...

  5. Flume基本概念

    1         Apache Flume 1.1         概述 Flume是Cloudera提供的一个高可用,高可靠的,分布式的海量日志采集.聚合和传输的软件. Flume的核心是把数据从 ...

  6. Binary search tree system and method

    A binary search tree is provided for efficiently organizing values for a set of items, even when val ...

  7. Linux轻松一下——cowsay命令,让动物说话

    Linux动物说话命令 使用方法 安装命令:sudo apt-get install cowsay 使用命令:cowsay hello 查看可选动物 cowsay -l 使用其他动物 cowsay - ...

  8. Linux下安装.bundle后缀的程序

    按照如下操作: #赋予可执行权限 sudo chmod +x XXXXX.bundle #使用root权限启动 sudo ./XXXXX.bundle

  9. Findbug插件静态java代码扫描工具使用

    本文转自http://blog.csdn.net/gaofuqi/article/details/22679609 感谢作者 FindBugs 是由马里兰大学提供的一款开源 Java静态代码分析工具. ...

  10. MyEclipse10及插件安装教程(附安装包和破解文件)

    MyEclipse10安装包+破解文件:MyEclipse10安装包.MyEclipse10破解文件MyEclipse10安装包地址:http://pan.baidu.com/s/1pJrCLB1My ...