zoukankan      html  css  js  c++  java
  • ado修改

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Data.SqlClient;
    
    namespace ConsoleApplication4
    {
        class Program
        {
            static void Main(string[] args)
            {
                //1、让用户输入要修改的学生编号
                Console.Write("请输入修改后的学生编号:");
                string scode = Console.ReadLine();
    
                Console.Write("请输入修改后的学生姓名:");
                string sname = Console.ReadLine();
    
                Console.Write("请输入修改后的学生性别:");
                bool ssex = Convert.ToBoolean(Console.ReadLine());
    
                Console.Write("请输入修改后学生生日:");
                DateTime sbirthday = Convert.ToDateTime(Console.ReadLine());
    
                Console.Write("请输入修改后学生分数:");
                decimal sscore = Convert.ToDecimal(Console.ReadLine());
    
    
                
                //2、执行修改
                //引用数据库命名空间
                //建立数据连接
                SqlConnection conn = new SqlConnection("server=.;database=data0425;user=sa;pwd=123;");
                //建立数据控制,在数据连接基础上
                SqlCommand cmd = conn.CreateCommand();
                //编写sql数据命令
                cmd.CommandText = "update student set name='" + sname + "',sex='" + ssex + "',bithday='" + sbirthday + "',score= " + sscore + " where code='" + scode + "'";
                //cmd.CommandText = "update student set name='" + sname + "',sex='" + ssex + "',birthday='" + sbirthday + "',score=" + sscore + " where code = '" + scode + "'";
    
                Console.WriteLine(cmd.CommandText);
                try
                {
                    //开启数据库
                    conn.Open();
                    //执行操作命令
                    cmd.ExecuteNonQuery();
                    //显示操作成功
                    Console.WriteLine("修改成功!");
    
                }
                catch
                {
                    Console.WriteLine("数据库连接失败!请重新连接!");
                }
                finally
                {
                    //关闭数据库
                    conn.Close();
                    Console.ReadLine();
                }
    
    
               
            }
        }
    }

  • 相关阅读:
    《PS技巧精华全部在这里!》
    c#的dictionary为什么在扩容时会以素数扩容
    初识Lua
    常用的排序
    像gal一样讲故事~
    打枪的实现
    武器的方向,人物和武器的翻转
    虚拟摇杆的修改
    实现虚拟摇杆的移动
    itemPool和MessageCenter
  • 原文地址:https://www.cnblogs.com/fengsantianya/p/5604596.html
Copyright © 2011-2022 走看看