zoukankan      html  css  js  c++  java
  • 封装数据库配置文件App配置文件

     <connectionStrings>
       <add name="strCon" connectionString="Data Source=.;Initial Catalog=DataManager;User ID=sa;Passwoed=lifatshit"/>
    </connectionStrings>

    封装表格

     public static DataTable ExecuteDateTable(string sql, params SqlParameter[] param)
            {
                DataTable dt = null;
                using(SqlConnection con=new SqlConnection(strCon))
                {
                    SqlCommand cmd = new SqlCommand(sql, con);
                    cmd.Parameters.AddRange(param);
                    using(SqlDataAdapter adapter=new SqlDataAdapter(cmd))
                    {
                        dt = new DataTable();
                        adapter.Fill(dt);
                    }
                }
                return dt;
            }

    //执行增删改 返回受影响的行数

    public static int ExecuteNonquery(string sql, params SqlParameter[] param)
            {
                int n = -1;
                using (SqlConnection con = new SqlConnection(strCon))
                {
                    using (SqlCommand cmd = new SqlCommand(sql, con))
                    {
                        con.Open();
                        cmd.Parameters.AddRange(param);
                        n = cmd.ExecuteNonQuery();
                    }
                }
                return n;
     
            }

     //执行查询 负责返回首行首列

    public static object ExecuteDcalar(string sql, params SqlParameter[] param)
            {
                object o = null;
                using(SqlConnection con=new SqlConnection (strCon))
                {
                    using(SqlCommand cmd=new SqlCommand (sql,con))
                    {
                        con.Open();
                        cmd.Parameters.AddRange(param);
                        o = cmd.ExecuteScalar();
                    }
                }
                return o;

    }

     //读取数据库

     public  static SqlDataReader ExecuteReader(string sql,params SqlParameter[] param)
            {
                SqlDataReader reader = null;
                using (SqlConnection con = new SqlConnection(strCon))
                {
                    using (SqlCommand cmd = new SqlCommand(sql, con))
                    {
                        con.Open();
                        cmd.Parameters.AddRange(param);
                        reader = cmd.ExecuteReader();
                    }
                }
                return reader;
            }

    重来没有接触过,零基础学习软件编程,一个字累
  • 相关阅读:
    Ui——创建视图的方法及过程
    iOS设计模式----原型模式
    浅谈OC中排序的方法
    Solid Dominoes Tilings (轮廓线dp打表 + 容器)
    Shell Necklace (dp递推改cdq分治 + fft)
    Rigid Frameworks (画图二分图规律 + DP + 数学组合容斥)
    PowMod (欧拉推式子 + 指数循环节)
    Necklace (全排列 + 匈牙利)
    GCD (RMQ + 二分)
    Game (思维)
  • 原文地址:https://www.cnblogs.com/hsha/p/4598749.html
Copyright © 2011-2022 走看看