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; } } }

}

最新文章

  1. PHP从PHP5.0到PHP7.1的性能全评测
  2. webpack脚手架搭建(简单版)
  3. ios 关键字 IB_DESIGNABLE IBInspectable 尝鲜
  4. Java Hour 18 来个CURD吧 (三)
  5. Redis应用
  6. windows Phone 浏览器窗口的尺寸
  7. selenium RC
  8. 验证SQLServer死锁进程
  9. 【CJOJ2440】大话西游(树链剖分)
  10. Spring Cloud Contract
  11. 携程Java后台开发三面面经
  12. Thread之八:interrupt中断
  13. 配置react-sass
  14. VXLAN
  15. 计算Python运行时间
  16. python 3.6.5 sys模块和os模块
  17. java内存的分配和管理
  18. 海康ipc onvif抓包分析
  19. Mysql5.7.22版本,插入中文乱码的问题
  20. 鲁宾斯坦说:"思维是在概括中完成的。"

热门文章

  1. element select下拉框绑定number类型
  2. linux 的sed命令解释 sed ':t;N;s/\n/,/;b t' 将换行符换成逗号
  3. Django cookie、session使用
  4. Python-程序的控制结构
  5. 清北学堂模拟赛d4t5 b
  6. hdu 4888 最大流给出行列和求矩阵
  7. 某种密码(password.*)
  8. org.hibernate.PropertyValueException: not-null property references a null or transient value: model.
  9. 2.5-冗余VLAN
  10. 我们的一个已投产项目的高可用数据库实战 - mongo 副本集的搭建具体过程