zoukankan      html  css  js  c++  java
  • 常用的查询的方法

    返回一个Table的方法!

       public static DataTable GetDataTable(string sql)
            {
                DataTable dt = new DataTable();
                if (!string.IsNullOrEmpty(sql))
                {
                    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbString"].ConnectionString);
    
                    try
                    {
                        conn.Open();
                        SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                        da.Fill(dt);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        conn.Close();
                    }
    
    
                }
    
                return dt;
            }

    返回受影响的行数!

    public static int ExecuteNonQuery(string sql, SqlParameter[] sqlParams)
            {
                int count = 0;
    
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbString"].ConnectionString);
    
                if (!string.IsNullOrEmpty(sql) && sqlParams != null && sqlParams.Length > 0)
                {
                    try
                    {
                        conn.Open();
                        SqlCommand cmd = new SqlCommand(sql, conn);
                        cmd.Parameters.AddRange(sqlParams);
                        count = cmd.ExecuteNonQuery();
    
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        conn.Close();
                    }
    
                }
    
                return count;
            }
  • 相关阅读:
    String类型操作命令及api使用
    回顾Redis基础
    kibana6 安装
    elasticsearch安装
    flink 异常
    Scala异常
    idea配置
    mysql error 1577解决
    Hbase与phoenix关联
    CS61b lab4打卡
  • 原文地址:https://www.cnblogs.com/xlwang/p/xlwang.html
Copyright © 2011-2022 走看看