数据库连接的方法

  // 执行非查询sql语句,并返回受影响的行数
        public static int ExecuteNonQuery(string sql, params SqlParameter[] sqlparams)
        {
            using (SqlConnection conn = new SqlConnection(ConStr))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(sql, conn))
                {
                    foreach (SqlParameter sqlparam in sqlparams)
                    {
                        cmd.Parameters.Add(sqlparam);
                    }
                    return cmd.ExecuteNonQuery();
                }
            }
        }

你可能感兴趣的:(数据库连接)