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
                conn.Close();
                Console.ReadKey();
            }
        }
    }                                                      

  • 相关阅读:
    Mybatis--->第五节注解完成增删改查
    Mybatis--->新增新功能报错,以前都正常,突然报错
    Mybatis--->limit分页查询
    固定套路--->log4j日志运用-Maven
    Mybatis第三节优化别名--->user
    Mybatis入门第二节--->优化
    Mybatis 报错 java.io.IOException: Could not find resource mybatis-config.xml
    学习Java的第十二天
    学习Java的第十一天
    学习Java的第十天
  • 原文地址:https://www.cnblogs.com/shirln/p/7875171.html
Copyright © 2011-2022 走看看