zoukankan      html  css  js  c++  java
  • MySql数据库封装MySqlDBHelper

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Data;
    using Newtonsoft.Json;
    using MySql.Data.MySqlClient;
    
    
    namespace DAL
    {
        public class MySqlDBHelper
        {
            private  MySqlConnection GetConnection()
            {
                return new MySqlConnection("server=127.0.0.1;uid=root;pwd=root;database=mmmm");
            }
    
    
            public int ExecuteNonQuery(string sql)
            {
                int result = 0;
                using (MySqlConnection con = GetConnection())
                {
                    con.Open();
                    MySqlCommand scom = new MySqlCommand(sql, con);
                    result =scom.ExecuteNonQuery();
                    con.Close();
                }
                return result;
            }
    
    
            public DataTable ExecuteQuery(string sql)
            {
                DataTable dt = new DataTable();
                using (MySqlConnection con = GetConnection())
                {
                    MySqlCommand scom = new MySqlCommand(sql, con);
                    MySqlDataAdapter ada = new MySqlDataAdapter(scom);
                    ada.Fill(dt);
                }
                return dt;
            }
    
    
            public List<T> ExecuteQueryList<T>(string sql)
            {
                DataTable dt = ExecuteQuery(sql);
                string json = JsonConvert.SerializeObject(dt);
                return JsonConvert.DeserializeObject<List<T>>(json);
            }
        }
    }
  • 相关阅读:
    python中的字典
    python中的元组操作
    python中的列表
    python中的内建函数
    python中格式化字符串
    34 哈夫曼编码
    33 构造哈夫曼树
    32 哈夫曼树
    31 树和森林的遍历
    30 森林和二叉树的转化(二叉树与多棵树之间的关系)
  • 原文地址:https://www.cnblogs.com/lhl123/p/10638390.html
Copyright © 2011-2022 走看看