使用c#进行数据库的增加删除修改查看数据

时间:2026-02-14 18:24:21

1、增加数据

使用c#进行数据库的增加删除修改查看数据

2、删除数据

使用c#进行数据库的增加删除修改查看数据

3、修改数据

public static void TestUpdate() //修改

        {

            //连接字符串

            string strcon = "server=.;database=chuanzhiboke;Integrated Security=True";

            //1、新建通道

            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = strcon;

            //2、准备新增sql命令

            string strcommand = "update T_TempEmployee set Fname = 'leqing' where FName = 'Fotifa' ";

            //3、新建命令对象,并前告诉它走那条路,做什么事情

            SqlCommand cmd = new SqlCommand(strcommand, conn);

            //4、打开通道

            conn.Open();

            //5、执行sql语句

            int intres = -1;

            intres = cmd.ExecuteNonQuery();

            //6、关闭连接通道

            conn.Close();

            if (intres > 0)

            {

                Console.WriteLine("修改成功");

            }

            else

            {

                Console.WriteLine("修改失败");

            }

        }

使用c#进行数据库的增加删除修改查看数据

© 2026 五度知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com