• SQL Server数据库中表的增、删、改


    通过SqlCommand对象的ExecuteNonQuery方法执行命令行,来实现数据库中表的增、删、改。主要有5步

    using System.Data.SqlClient;//载入数据库命名空间
            private void button1_Click(object sender, EventArgs e)
            {
                //1、连接数据库
                SqlConnection con = new SqlConnection("Server=CAIWU;User Id=sa;Pwd=;DataBase=db_Me");
                //命令行语句,在表中添加内容。'"+string格式内容+"',"+数字格式内容+"
                string strInsert = "insert into dbo.Table_2(Name,Price) values('"+textBox1.Text+"',"+Convert.ToInt32(textBox2.Text)+")";
                //2、加入命令行语句
                SqlCommand com = new SqlCommand(strInsert, con);
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();//3、打开数据库连接
                }//4、SqlCommand对象的ExecuteNonQuery方法执行命令行,并返回受影响的行数
                if (Convert.ToInt32(com.ExecuteNonQuery()) > 0)
                {
                    label3.Text = "添加成功!";
                }
                else
                {
                    label3.Text = "添加失败!";
                }
                con.Close();//5、关闭数据库连接
            }

         

    其他详情可参考:

    https://blog.csdn.net/c1481118216/article/details/51766590?utm_source=blogkpcl12

    https://www.cnblogs.com/daxueshan/p/6687521.html

  • 相关阅读:
    ural 1723 Sandro's Book
    ural 1104 Don’t Ask Woman about Her Age
    ural 1052 Rabbit Hunt
    ural 1837 Isenbaev's Number
    ural 1348 Goat in the Garden 2
    ural 1207 Median on the Plane
    ural 1640 Circle of Winter
    段错误 核心已转储尝试解决
    显卡相关命令介绍【转载】
    Linux的top命令学习【转载】
  • 原文地址:https://www.cnblogs.com/xixixing/p/10650181.html
Copyright © 2020-2023  润新知