• 网络游戏_数据库更新


    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();
            }
        }
    }                                                      

  • 相关阅读:
    华南虎原图找到了
    电脑高手的7大标准
    科幻小说一代宗师阿瑟•克拉克过逝
    看英文片最容易误解的10个单词(感觉对大家很有用,转过来的)
    地震了,人跑的真快啊
    John Titor一个来自未来的人
    马云扮白雪公主
    世界上最冷的脑筋急转弯
    告别人肉刷,让房源自己送上门
    来测下你的浏览器对标准的支持情况吧
  • 原文地址:https://www.cnblogs.com/shirln/p/7875240.html
Copyright © 2020-2023  润新知