zoukankan      html  css  js  c++  java
  • VS 使用Sql Server 数据库增删改查

        /// <summary>
            /// 执行查询语句,返回DataSet
            /// </summary>
            /// <param name="SQLString">查询语句</param>
            /// <returns>DataSet</returns>
            public DataSet Query(string SQLString, params SqlParameter[] cmdParms)
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    SqlCommand cmd = new SqlCommand(SQLString, connection);
                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        DataSet ds = new DataSet();
                        try
                        {
                            da.Fill(ds, "ds");
                            cmd.Parameters.Clear();
                        }
                        catch (System.Data.SqlClient.SqlException ex)
                        {
                            throw new Exception(ex.Message);
                        }
                        return ds;
                    }
                }
            }
    
            /// <summary>
            /// 执行SQL语句,返回影响的记录数
            /// </summary>
            /// <param name="SQLString">SQL语句</param>
            /// <returns>影响的记录数</returns>
            public int ExecuteSql(string SQLString, params SqlParameter[] cmdParms)
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    using (SqlCommand cmd = new SqlCommand(SQLString,connection))
                    {
                        try
                        {
                            if (connection.State != ConnectionState.Open)
                                connection.Open();
                            int rows = cmd.ExecuteNonQuery();
                            cmd.Parameters.Clear();
                            return rows;
                        }
                        catch (System.Data.SqlClient.SqlException e)
                        {
                            throw e;
                        }
                    }
                }
            }
  • 相关阅读:
    less-循环写法
    利用IntersectionObserver完成懒加载、加载更多
    通过is切换组件
    css3-背景渐变
    css-六边形、平行四边形、扇形实现
    vue-利用递归组件完成一个树形组件
    event loop 事件循环
    vue-组件间通信
    video 背景图平铺
    JS 事件委托
  • 原文地址:https://www.cnblogs.com/gates/p/3612244.html
Copyright © 2011-2022 走看看