zoukankan      html  css  js  c++  java
  • 网络游戏_数据库更新

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using MySql.Data.MySqlClient;

    namespace MySql数据库操作
    {
        class Program
        {
            static void Main(string[] args)
            {
                string connStr = "Database=game;Data Source=127.0.0.1;port=3306;User Id=root;Password=shirln123My;";
                MySqlConnection conn = new MySqlConnection(connStr);
                conn.Open();

                #region 查询
                // MySqlCommand cmd = new MySqlCommand("select * from user where id=1", conn);
                // MySqlDataReader reader = cmd.ExecuteReader();
                //while(reader.Read())
                // {              
                //     string username = reader.GetString("username");
                //     string password = reader.GetString("password");
                //     Console.WriteLine(username+";"+password);

                // }
                // reader.Close();
                #endregion

                #region 插入
                //string username = "cwer";
                //string password = "qwedv';delete  from user;";
                ////MySqlCommand cmd = new MySqlCommand("insert into user set username='" + username + "'" + ",password='" + password + "'", conn);
                ////cmd.ExecuteNonQuery();
                //MySqlCommand cmd = new MySqlCommand("insert into user set username=@un,password=@pwd", conn);
                //cmd.Parameters.AddWithValue("un", username);
                //cmd.Parameters.AddWithValue("pwd", password);
                //cmd.ExecuteNonQuery();
                #endregion

                #region 删除
                //MySqlCommand cmd = new MySqlCommand("delete from user where id=@id", conn);
                //cmd.Parameters.AddWithValue("id", 10);
                //cmd.ExecuteNonQuery();
                #endregion

                #region 更新
                MySqlCommand cmd = new MySqlCommand("update user set username=@un where id=11", conn);
                cmd.Parameters.AddWithValue("un", "shirln");
                cmd.ExecuteNonQuery();
                #endregion

                conn.Close();
                Console.ReadKey();
            }
        }
    }                                                      

  • 相关阅读:
    tp5 phpstudy配置问题
    无限级分类的写法
    使用微信共众号 提供网页登陆接口
    destoon数据库表说明汇总如下
    destoon 配置文件config.inc.php参数说明
    destoon二次开发流量
    thinkphp5 模型读取器和修改器
    thinkphp5 模型的 删作操作
    thinkphp5 模型的 查询操作
    轻松搞定数据验证(三)
  • 原文地址:https://www.cnblogs.com/shirln/p/7875240.html
Copyright © 2011-2022 走看看