ADO.NET 增删查改小总结
转自:http://www.cnblogs.com/ashu123/archive/2010/10/10/ado_1.html
三套路-----增删改
1 using System.Data.SqlClient;
2
3 SqlConnection conn =new SqlConnection("xxx");
4
5
6 string sql ="xxx";
7
8 SqlCommand comm =new SqlCommand(sql, conn);
9
10 conn.Open();
11
12 comm.ExecuteNonQuery();
13
14 conn.Close();
三套路-----查(绑定到DataGridView
1 using System.Data.SqlClient;
2
3 SqlConnection conn =new SqlConnection("xxx");
4
5 string sql ="xxx";
6
7 SqlDataAdapter da =new SqlDataAdapter(sql, conn);
8
9 DataSet ds =new DataSet();
10
11 da.Fill(ds);
12
13 dataGridView1.DataSource = ds.Tables[0];
14
15 //要更新 查询语句要 查询主键列
16
17 SqlCommandBuilder sd =new SqlCommandBuilder(da);
18
19 da.Update(ds.Tables[0]);
三套路----查(绑定到ListView)
using System.Data.SqlClient;
SqlConnection conn =new SqlConnection("xxx");
string sql ="xx";
SqlCommand comm =new SqlCommand(sql, conn);
conn.Open();
SqlDataReader read = comm.ExecuteReader();
while (read.Read())
{
ListViewItem lvi =new ListViewItem(read["xxx"].ToString());
lvi.Tag = read["id"];
listView1.Items.Add(lvi);
lvi.SubItems.AddRange(new String[] { read["xxx"].ToString() });
}
read.Close();
conn.Close();
ADO.NET 增删查改小总结的更多相关文章
- ADO.NET教程(2)实现增删查改
声明一个类,在类中实现增删查改的方法 public class AdoNet { //声明连接字符串 public string Sqlstr = "data source={0};data ...
- knockout+MVC+webapi+sqlserver完成增删查改
快过年了,公司的事情较少,想着开始学习点新东西.这段时间一个项目用到了mvc和webapi,然后一直对knockout比较感兴趣,就想着用这个框架做一个小实例.数据库采用的是sqlserver.话不多 ...
- 6.在MVC中使用泛型仓储模式和依赖注入实现增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...
- 3.EF 6.0 Code-First实现增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-entity-framework-5-0-code- ...
- 4.在MVC中使用仓储模式进行增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-using-the-repository-pattern-in-mvc/ 系列目录: ...
- 5.在MVC中使用泛型仓储模式和工作单元来进行增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...
- jdbc的实例应用:增删查改实现
//在jdbc中进行增删查改 //查看所有 public static void findAll() { String url = "jdbc:mysql://localhost:3306/ ...
- 用javascript实现html元素的增删查改[xyytit]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- hibernate基础增删查改简单实例
hibernate 基础理论知识网上很多,可以百度和google.这里不做多的介绍,以一个User表来开展例子 建一个web-project 我这里用了junit单元测试环境来进行增删查改的测试,别的 ...
随机推荐
- 接口(工厂模式&代理模式)
程序1:简单的接口功能 package com.liaojianya.chapter2; /** * 编写程序实现一个usb接口,定义设备来使用这个接口,从而计算机可以调用具有usb接口的设备. * ...
- linux 学习一
linux 命令 ls -al ls -l cal
- Parameters
Quote from: http://ss64.com/nt/syntax-args.html Parameters A parameter (or argument) is any value pa ...
- jquery-ui-datepicker定制化,汉化,因手机布局美观化源码修改
感谢浏览,欢迎交流=.= 公司微信网页需要使用日历控件,想到jquery-mobile,但是css影响页面布局,放弃后使用jquery-ui-datepicker. 话不多说,进入正题: 1.jque ...
- wamp集成环境php多版本搭建(php5.5,php5.6,php7.0.6)
首先需要搭建的版本可以在php官方(http://windows.php.net/download)下载对应的版本,X86对应的是32位操作系统,X64对应的是64位操作系统. 1:下载 ...
- sql 自身连接
"select table1.field1, table2.field1 from table table1, table table2 where table1.id=table2.par ...
- less学习-语法(二)
变量 @color1:#fff; 选择器 // Variables @mySelector: banner; // Usage .@{mySelector} { font-weight: bold; ...
- notepad++ :正则表达式系统教程
前言&索引 前言 正则表达式是烦琐的,但是强大的,学会之后的应用会让你除了提高效率外,会给你带来绝对的成就感.只要认真去阅读这些资料,加上应用的时候进行一定的参考,掌握正则表达式不是问题. 索 ...
- C# 操作XML文件,用XML文件保存信息
using System; using System.Collections.Generic; using System.Text; using System.Xml; using System.IO ...
- POJ 1961 Period KMP算法next数组的应用
题目: http://poj.org/problem?id=1961 很好的题,但是不容易理解. 因为当kmp失配时,i = next[i],所以错位部分就是i - next[i],当s[0]...s ...