C# MySqlHelper
来源:互联网 发布:淘宝的红包怎么领取 编辑:程序博客网 时间:2024/04/28 03:36
using System;using System.Collections.Generic;using System.Linq;using System.Text;using MySql.Data.MySqlClient;using System.Data;class MySqlHelper:IDisposable { private MySqlConnection m_conn = null; private MySqlTransaction m_trans = null; private bool m_tran_enabled = false; public MySqlHelper() { m_conn = new MySqlConnection(); m_conn.ConnectionString = "Server=192.168.1.14;Port=3308;Uid=root;Pwd=123654"; m_conn.Open(); } public void BeginTrans() { m_trans = m_conn.BeginTransaction(); m_tran_enabled = true; } public void Commit() { if (m_trans != null && m_tran_enabled) { m_tran_enabled = false; m_trans.Commit(); } } public void Rollback() { if (m_trans != null && m_tran_enabled) { m_tran_enabled = false; m_trans.Rollback(); } } public object QuerySome(string sql,int fieldindex) { using (MySqlCommand cmd = new MySqlCommand(sql, m_conn)) { using (MySqlDataReader sr = cmd.ExecuteReader()) { if (sr.Read()) { return sr.GetValue(fieldindex); } } } return null; } public delegate void FillValues(MySqlDataReader sr); public void QuerySomes(string sql, FillValues fill) { using (MySqlCommand cmd = new MySqlCommand(sql, m_conn)) { using (MySqlDataReader sr = cmd.ExecuteReader()) { fill(sr); } } } public DataTable Source(string sql) { DataTable dt = null; MySqlCommand cmd = null; MySqlDataAdapter ad = null; try { lock (dt = new DataTable()) { cmd = new MySqlCommand(sql, m_conn); ad = new MySqlDataAdapter((MySqlCommand)cmd); dt.Clear(); ad.Fill(dt); } } catch (Exception e) { throw e; } return dt; } public void ExecProc(string proc, params MySqlParameter[] ps) { using (MySqlCommand cmd = new MySqlCommand(proc, m_conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; foreach (MySqlParameter p in ps) { cmd.Parameters.Add(p); } cmd.ExecuteNonQuery(); } } void IDisposable.Dispose() { m_conn.Close(); m_conn.Dispose(); if (m_trans != null) { m_trans.Dispose(); } } }
0 0
- C# MySqlHelper
- C# MySqlHelper
- MySqlHelper
- MySqlHelper
- MySQLHelper
- MySqlHelper
- MysqlHelper
- MySQLHelper
- MysqlHelper.cs(C# 调用MySql数据库)
- C# 基于MySQL的数据层基类(MySQLHelper)
- MysqlHelper.cs(C# 调用MySql数据库)
- 封装类之MYSQLHelper(C#连接MySql数据库)
- C#通过MySqlHelper进行多条数据查询
- MySqlHelper备份
- .net / MySQLHelper
- .net core 2.0 下,用C#自创实现MysqlHelper的ExecuteDataTable 功能[2017-10-30]
- SqlHelper和MySqlHelper
- MySqlHelper代码积累
- iphone6以及iphone6plus适配
- Contains Duplicate
- MySQL延迟更新索引(delay_key_write)
- 5个替代Apache和IIS的轻量级网络服务器
- 火眼金睛 | 应用崩溃惯用三大杀招,你中招了么?
- C# MySqlHelper
- mysql 允许远程登录配置
- mysql数据库错误解决方法
- Java基础——IO(二)——File类、Properties类、打印流、序列流(合并流)
- 二进制实现权限验证
- C# MySqlHelper
- 初识EF(一)
- LeetCode之TwoSum
- Android 自定义ScrollView ListView 体验各种纵向滑动的需求