-
Mysql操作类封装【https://blog.csdn.net/blog_lee/article/details/45111489】
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data;
- using System.Configuration;
- using System.Windows.Forms;
-
- using MySql.Data.MySqlClient;
- using System.Xml;
- using MySql.Data;
-
-
- namespace Common
- {
- public class DbManager
- {
-
- private string connStr;
- public string ConnStr
- {
- get { return this.connStr; }
- set { this.connStr = value; }
- }
-
- private DbManager() { }
-
-
- private static DbManager _instance = null;
- public static DbManager Ins
- {
- get { if (_instance == null) { _instance = new DbManager(); } return _instance; }
- }
-
-
-
-
-
-
-
- public DataSet ExecuteDataSet(string sql, params MySqlParameter[] paras)
- {
- using (MySqlConnection con = new MySqlConnection(ConnStr))
- {
-
- MySqlDataAdapter sqlda = new MySqlDataAdapter(sql, con);
- sqlda.SelectCommand.Parameters.AddRange(paras);
- DataSet ds = new DataSet();
- sqlda.Fill(ds);
- return ds;
-
- }
- }
-
-
-
-
-
-
-
- public DataTable ExcuteDataTable(string sql, params MySqlParameter[] paras)
- {
- using (MySqlConnection con = new MySqlConnection(ConnStr))
- {
- MySqlDataAdapter sqlda = new MySqlDataAdapter(sql, con);
- sqlda.SelectCommand.Parameters.AddRange(paras);
- DataTable dt = new DataTable();
- sqlda.Fill(dt);
- return dt;
- }
- }
-
-
-
-
-
-
-
- public object ExecuteScalar(string SQLString, params MySqlParameter[] paras)
- {
- using (MySqlConnection connection = new MySqlConnection(ConnStr))
- {
- using (MySqlCommand cmd = new MySqlCommand(SQLString, connection))
- {
- try
- {
- connection.Open();
- cmd.Parameters.AddRange(paras);
- object obj = cmd.ExecuteScalar();
- if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
- {
- return null;
- }
- else
- {
- return obj;
- }
- }
- catch (MySql.Data.MySqlClient.MySqlException e)
- {
- connection.Close();
- throw e;
- }
- }
- }
- }
-
-
-
-
-
-
- public int ExecuteNonquery(string sql, params MySqlParameter[] paras)
- {
- using (MySqlConnection con = new MySqlConnection(ConnStr))
- {
- MySqlCommand cmd = new MySqlCommand(sql, con);
- cmd.Parameters.AddRange(paras);
- con.Open();
- return cmd.ExecuteNonQuery();
- }
- }
-
-
-
-
-
-
-
- public int ExecuteProcNonQuery(string procname, params MySqlParameter[] paras)
- {
- using (MySqlConnection con = new MySqlConnection(ConnStr))
- {
- MySqlCommand cmd = new MySqlCommand(procname, con);
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.AddRange(paras);
- con.Open();
- return cmd.ExecuteNonQuery();
- }
- }
-
-
-
-
-
-
-
- public DataTable ExecuteProcQuery(string procname, params MySqlParameter[] paras)
- {
- using (MySqlConnection con = new MySqlConnection(ConnStr))
- {
- MySqlCommand cmd = new MySqlCommand(procname, con);
- cmd.CommandType = CommandType.StoredProcedure;
- MySqlDataAdapter sqlda = new MySqlDataAdapter(procname, con);
- sqlda.SelectCommand.Parameters.AddRange(paras);
- DataTable dt = new DataTable();
- sqlda.Fill(dt);
- return dt;
- }
- }
-
-
-
-
-
-
- public bool ExcuteCommandByTran(params MySqlCommand[] cmds)
- {
- using (MySqlConnection con = new MySqlConnection(ConnStr))
- {
- con.Open();
- MySqlTransaction tran = con.BeginTransaction();
- foreach (MySqlCommand cmd in cmds)
- {
- cmd.Connection = con;
- cmd.Transaction = tran;
- cmd.ExecuteNonQuery();
- }
- tran.Commit();
- return true;
- }
- }
-
-
- public DataTable ExcuteDataWithPage(string sql, ref int totalCount, params MySqlParameter[] paras)
- {
- using (MySqlConnection con = new MySqlConnection(ConnStr))
- {
- MySqlDataAdapter dap = new MySqlDataAdapter(sql, con);
- DataTable dt = new DataTable();
- dap.SelectCommand.Parameters.AddRange(paras);
- dap.Fill(dt);
- MySqlParameter ttc = dap.SelectCommand.Parameters["@totalCount"];
- if (ttc != null)
- {
- totalCount = Convert.ToInt32(ttc.Value);
- }
- return dt;
- }
- }
-
- }
- }
- DbManager.Ins.ConnStr = "Mysql地址 密码等"
- string sql = @"select * from log_account where (createtime between @startTime and @endTime) and (serverinfo like @serverinfo)";
- List<MySqlParameter> Paramter = new List<MySqlParameter>();
- Paramter.Add(new MySqlParameter("@startTime", startTime));
- Paramter.Add(new MySqlParameter("@endTime", endTime));
- Paramter.Add(new MySqlParameter("@serverinfo", (ConfManager.Ins.currentConf.serverid + "-%")));
- DataTable data = DbManager.Ins.ExcuteDataTable(sql, Paramter.ToArray());
-
相关阅读:
fiddler抓取java系程序的网络通信
ZOJ 2724 Windows Message Queue(优先队列)
FZU 电动车通行证制度
Havel定理
Catch That Cow
Trie树
zoj 2876 Phone List
zoj 2420
getchar
zoj 1315 Excuses, Excuses!
-
原文地址:https://www.cnblogs.com/jingxuan-li/p/8653747.html
Copyright © 2020-2023
润新知