zoukankan      html  css  js  c++  java
  • MysqlDbHelper

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    //引用命名空间
    using MySql.Data.MySqlClient;
    using MySql.Data;
    using System.Data;
    
    namespace DAL
    {
        public class MySqlDbHelper
        {
            //连接数据库
            //MySqlConnection conn = new MySqlConnection("");
            //public static string connection = "";
            static string connectionStrings = "Server=127.0.0.1;Database=周考三;Uid=root;Pwd=root;";
    
    
    
            /// <summary>
            ///         利用存储过程 返回受影响行数  添加  删除  修改
            /// </summary>
            /// <param name="parameter"></param>
            /// <param name="procName"></param>
            /// <returns></returns>
            public static int ProcProcExecuteNonQuery(CommandType commType,string procName, MySqlParameter[] parm=null)
            {
                using (MySqlConnection conn=new MySqlConnection(connectionStrings))
                {
                    MySqlCommand cmd = new MySqlCommand(procName);
                    cmd.Connection = conn;
                    conn.Open();
                    cmd.CommandType = commType;
                    if (parm!=null )
                    {
                        cmd.Parameters.AddRange(parm);
                    }
                    int i = cmd.ExecuteNonQuery();
                    return i;
                }
                
    
            }
    
            /// <summary>
            ///         利用存储过程,返回一行一列
            /// </summary>
            /// <param name="procName"></param>
            /// <param name="parameter"></param>
            /// <returns></returns>
            public static object ProcExecuteScalar(CommandType commType, string procName, MySqlParameter[] parm = null)
            {
                using (MySqlConnection conn = new MySqlConnection(connectionStrings))
                {
                    MySqlCommand cmd = new MySqlCommand(procName);
                    cmd.Connection = conn;
                    conn.Open();
                    cmd.CommandType = commType;
                    if (parm != null)
                    {
                        cmd.Parameters.AddRange(parm);
                    }
                    object  obj = cmd.ExecuteScalar();
                    return obj;
                }
            }
    
            /// <summary> 
            ///         利用存储过程,获取数据表  查询  显示
            /// </summary>
            /// <param name="procName"></param>
            /// <param name="parm"></param>
            /// <returns></returns>
            public static DataTable ProcDataAdapter(CommandType commType, string procName, MySqlParameter[] parm = null)
            {
                using (MySqlConnection conn = new MySqlConnection(connectionStrings))
                {
                    DataTable dt = new DataTable("com");
                    MySqlCommand cmd = new MySqlCommand(procName);
                    cmd.Connection = conn;
                    conn.Open();
                    cmd.CommandType = commType;
                    if (parm!=null)
                    {
                        cmd.Parameters.AddRange(parm);
                    }
                    MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                    da.Fill(dt);
                    return dt;
                }
            }
        }
    }
  • 相关阅读:
    vim delete
    npm ERR! network connect ETIMEDOUT
    在 ubuntu 14.04 Unity 中清除和关闭 Totem 播放记录
    ubuntu 14.04 上 jvpn 使用说明
    LWP::Protocol::https not installed
    perl 安装模块
    触摸屏工作方式
    如何检测死锁并快速定位死锁位置
    如何用 yum 的一个包替换另一个包
    shell 中 here documemt << 与 <<- 的区别
  • 原文地址:https://www.cnblogs.com/gbb44/p/10643010.html
Copyright © 2011-2022 走看看