MySql c#通用类
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#通用类的更多相关文章
- MySql c#通用类 转
using System;using System.Data;using System.Configuration;using System.Collections.Generic;using Sys ...
- C#---数据库访问通用类、Access数据库操作类、mysql类 .[转]
原文链接 //C# 数据库访问通用类 (ADO.NET)using System;using System.Collections.Generic;using System.Text;using Sy ...
- C#---数据库访问通用类、Access数据库操作类、mysql类 .
//C# 数据库访问通用类 (ADO.NET)using System;using System.Collections.Generic;using System.Text;using System. ...
- C#操作SqlServer MySql Oracle通用帮助类
C#操作SqlServer MySql Oracle通用帮助类 [前言] 作为一款成熟的面向对象高级编程语言,C#在ADO.Net的支持上已然是做的很成熟,我们可以方便地调用ADO.Net操作各类关系 ...
- MySQL数据库工具类之——DataTable批量加入MySQL数据库(Net版)
MySQL数据库工具类之——DataTable批量加入数据库(Net版),MySqlDbHelper通用类希望能对大家有用,代码如下: using MySql.Data.MySqlClient; us ...
- SpringBoot 2.0 mybatis mapper通用类
<!---mybatis通用类包含mybatis和连接池 mybatis和连接池就不需要引入--> <dependency> <groupId>tk.mybatis ...
- (一 、上)搭建简单的SpringBoot + java + maven + mysql + Mybatis+通用Mapper 《附项目源码》
最近公司一直使用 springBoot 作为后端项目框架, 也负责搭建了几个新项目的后端框架.在使用了一段时间springBoot 后,感觉写代码 比spring 更加简洁了(是非常简洁),整合工具也 ...
- 第一天:java与mysql的连接工具类
第一天:java与mysql的连接工具类 java最新版马上就要收费,这无疑是这门语言的衰败起始,毕竟在中国收费便难发展,例如c#,但是毕业设计已经选好用java来写一个动态网站, 这已经是一个事实, ...
- springboot学习笔记:8. springboot+druid+mysql+mybatis+通用mapper+pagehelper+mybatis-generator+freemarker+layui
前言: 开发环境:IDEA+jdk1.8+windows10 目标:使用springboot整合druid数据源+mysql+mybatis+通用mapper插件+pagehelper插件+mybat ...
随机推荐
- Sping bean的作用域
单例(Singleton):在整个应用中,只创建bean的一个实例.(默认) 原型(Prototype):每次注入或者通过Sping应用上下文获取的时候,都会创建一个新的bean. 回话(Sessio ...
- unzip 命令巧用举例
1.把文件解压到当前目录下 unzip master.zip 2.如果要把文件解压到指定的目录下,需要用到-d参数. unzip -d /tmp master.zip 3.解压的时候,有时候不想覆盖已 ...
- 关于static关键字的思考
静态方法是否能调用非静态成员变量? static关键字具有如下特点: 一.static关键字修饰的属性/方法可以通过类名直接调用,而不必先new一个对象. 二.sta ...
- DOM节点的获取
document.getElementById();//id名,在实际开发中较少使用,选择器中多用class id一般只用在顶级层存在 不能太过依赖id document.getElements ...
- 使用 Cordova 打包 app
1.安装nodejs 2.安装 cordova npm install -g cordova 3.Cordova 打包成安卓APK需要用到ANT打包工具,首先配置好java环境: 下载安装Java J ...
- python之cookbook-day04
第一章:数据结构和算法 1.4 查找最大或最小的N个元素 问题: 怎样从一个集合中获得最大或者最小的 N 个元素列表? 解决方案: heapq 模块有两个函数:nlargest() 和 nsmalle ...
- Modbus 协议解析
- SFTP文件上传下载
http://www.cnblogs.com/longyg/archive/2012/06/25/2556576.html (转载)
- Ubuntu | Flask + Gunicorn + Nginx 部署服务器环境
现在我们手里有一个准备发布的项目,那么如何将他上传到你的服务器,并让外网访问呢? 前提: 1. 安装了Python环境 apt-get install python-dev 2. 安装Flask pi ...
- poj3233 题解 矩阵乘法 矩阵快速幂
题意:求S = A + A2 + A3 + … + Ak.(mod m) 这道题很明显可以用矩阵乘法,但是这道题的矩阵是分块矩阵, 分块矩阵概念如下:当一个矩阵A中的单位元素aij不是一个数值而是一个 ...