zoukankan      html  css  js  c++  java
  • ADO.NET怎删改+vs 2013 C#

              一、删除

                string constr = "server=.;database=test;uid=sa;pwd=sa";
                SqlConnection myconnection = new SqlConnection(constr);
                myconnection.Open();
                string sql = "delete from students where ID=5";
                SqlCommand sc = new SqlCommand(sql,myconnection);
                sc.ExecuteNonQuery();
                SqlDataAdapter sda = new SqlDataAdapter("select * from students",myconnection);
                System.Data.DataSet dr = new System.Data.DataSet();
                sda.Fill(dr,"students");
                sda.Update(dr,"students");
                ViewBag.students = dr.Tables[0];
                return View();
                


    二、插入
                string constr = "server=.;database=test;uid=sa;pwd=sa";
                SqlConnection myconnection = new SqlConnection(constr);
                myconnection.Open();
                string sql1 = "insert into students(sno,name,sex,age) values('101411','历历','男','18')";
                SqlCommand sc = new SqlCommand(sql1, myconnection);
                sc.ExecuteNonQuery();
                string sql = "select * from students";
                SqlDataAdapter sda = new SqlDataAdapter(sql,myconnection);
                System.Data.DataSet ds = new System.Data.DataSet();
                sda.Fill(ds,"students");
                ViewBag.students = ds.Tables[0];
                return View();




    三、更新
                string constr = "server=.;database=test;uid=sa;pwd=sa";
                SqlConnection myconnection = new SqlConnection(constr);
                myconnection.Open();
                string sql1 = "update students set sno='1',name='华华' where ID=2";
                SqlCommand sc = new SqlCommand(sql1, myconnection);
                sc.ExecuteNonQuery();
                string sql = "select * from students";
                SqlDataAdapter sda = new SqlDataAdapter(sql, myconnection);
                System.Data.DataSet ds = new System.Data.DataSet();
                sda.Fill(ds, "students");
                ViewBag.students = ds.Tables[0];
                return View();

  • 相关阅读:
    【解决】Ubuntu命令行弹出光驱的方法
    【8086汇编基础】02寻址方式和MOV指令
    【8086汇编基础】03变量、数组和常量的处理
    Ubuntu12.10 内核源码外编译 linux模块编译驱动模块的基本方法
    【8086汇编基础】05常用函数库文件emu8086.inc
    Ubuntu12.10 使用DNW传数据 进行ARM开发板烧写
    【8086汇编基础】04中断
    【8086汇编基础】01汇编语言简要介绍
    飞凌OK6410开发板移植uboot官方最新版uboot2012.10.tar.bz2
    【8086汇编基础】00基础知识各种进制的数据
  • 原文地址:https://www.cnblogs.com/dingfangbo/p/5769495.html
Copyright © 2011-2022 走看看