zoukankan      html  css  js  c++  java
  • SqlHelper

    private static readonly string str = ConfigurationManager.ConnectionStrings["strCon"].ConnectionString;
            public static DataTable GetTable(string sql)
            {
                DataTable dt = new DataTable();
                using (SqlDataAdapter sda = new SqlDataAdapter(sql, str))
                {
                    sda.Fill(dt);
                }
                return dt;
            }
            public static int ExecuteNonQuery(string sql, params SqlParameter[] param)
            {
                using (SqlConnection con = new SqlConnection(str))
                {
                    using (SqlCommand cmd = new SqlCommand(sql, con))
                    {
                        cmd.Parameters.AddRange (param);
                        con.Open();
                        return cmd.ExecuteNonQuery();
                    }
                }
            }
            public static object ExecuteScalar(string sql, params SqlParameter[] param)
            {
                using (SqlConnection con = new SqlConnection(str))
                {
                    using (SqlCommand cmd = new SqlCommand(sql, con))
                    {
                        cmd.Parameters.AddRange  (param);
                        con.Open();
                        return cmd.ExecuteScalar();
                    }
                }
            }
            public static SqlDataReader ExecuteReader(string sql, params SqlParameter[] param)
            {
                SqlConnection con = new SqlConnection(str);

                using (SqlCommand cmd = new SqlCommand(sql, con))
                {
                    cmd.Parameters.AddRange(param);
                    try
                    {
                        con.Open();
                        return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }

  • 相关阅读:
    Monggodb基础
    手游运营数据指标
    JSON语法
    Java中日期转换问题
    Java线程中锁的问题
    鼠标移动监听的注意事项
    链接数据库的问题
    获取显示器的宽高
    JTable的使用问题
    JScrollPane控件中添加其他控件的问题&&JScrollPane设置滚动条&&调整滚动速度
  • 原文地址:https://www.cnblogs.com/crazyair/p/3638102.html
Copyright © 2011-2022 走看看