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();
ADO.NET怎删改+vs 2013 C#的更多相关文章
- ADO.NET 增删改查的基本用法
ADO.NET:数据访问技术 就是将C#和MSSQL连接起来的一个纽带 可以通过ADO.NET将内存中的临时数据写入到数据库中也可以将数据库中的数据提取到内存中供程序调用 所有数据访问技术的基础 连接 ...
- Ado.net[增删改查,GET传值]
1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.c ...
- ado.net增删改查操作
ado.net是数据库访问技术将数据库中的数据,提取到内存中,展示给用户看还可以将内存中的数据写入数据库中去 并不是唯一的数据库访问技术,但是它是最底层最基础的数据库访问技术 使用ado.net对数据 ...
- ADO.NET增删改-------跟查不一样
建立数据库 create database ren go use database go create table user ( code nvarchar(20) primary key,--编号 ...
- ADO.NET 增删改、查
数据访问 对应命名空间:System.Data.SqlClient; SqlConnection:连接对象SqlCommand:命令对象SqlDataReader:读取器对象 CommandText: ...
- ADO.net 增删改查
ADO.net 一.定义:编程开发语言与数据库连接的一门语言技术 二.链接: 在vs中操作数据库需在开头进行链接 链接内容:using System.Data.SqlClient 三.引用数据库: 四 ...
- LinQ和ADO.Net增删改查 备忘
是否些倦了 SqlConnection conn=new SqlConnection();一系列繁冗的代码? 来试试Linq吧 查: using System.Data.SqlClient; name ...
- ado.net增删改查练习
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- ado.net(增删改)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
随机推荐
- C++ ------ 创建对象 new 和不 new 的区别
1.作用域不同 不用new:作用域限制在定义类对象的方法中,当方法结束时,类对象也被系统释放了,(安全不会造成内存系统泄漏). 用new:创建的是指向类对象的指针,作用域变成了全局,当程序结束时,必须 ...
- == 和 equals,equals 与 hashcode,HashSet 和 HashMap,HashMap 和 Hashtable
一:== 和 equals == 比较引用的地址equals 比较引用的内容 (Object 类本身除外) String obj1 = new String("xyz"); Str ...
- 「LibreOJ β Round #4」求和
https://loj.ac/problem/528 1 , d =1 μ(d)= (-1)^k , d=p1*p2*p3*^pk pi为素数 0 ...
- zoj 3229 Shoot the Bullet(有源汇上下界最大流)
Shoot the Bullethttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3442 Time Limit: 2 Second ...
- Python学习笔记(四十七)SMTP发送邮件
摘抄自:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432005226 ...
- IO流-读取写入缓冲区
例如FileReader和FileWriter在读取的时候是读一次或者写一次就请求磁盘,这样使用的时间非常的长,效率比较低,因此引入BufferedReader和BufferedWriter作为读取和 ...
- NSPredicate--谓词(is)
技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong NSPredicate 技术博客http:// ...
- python模块之imghdr检测图片类型
1. imghdr是什么 imghdr是一个用来检测图片类型的模块,传递给它的可以是一个文件对象,也可以是一个字节流. 能够支持的图片格式: 2. 如何使用 提供了一个api叫做imghdr.what ...
- koa源码阅读[2]-koa-router
koa源码阅读[2]-koa-router 第三篇,有关koa生态中比较重要的一个中间件:koa-router 第一篇:koa源码阅读-0第二篇:koa源码阅读-1-koa与koa-compose k ...
- hdu 3729 I'm Telling the Truth(二分匹配_ 匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3729 I'm Telling the Truth Time Limit: 2000/1000 MS ( ...