首页 > Web开发 > 详细

ADO.NET 增删查改小总结

时间:2014-03-07 18:52:31      阅读:379      评论:0      收藏:0      [点我收藏+]

转自:http://www.cnblogs.com/ashu123/archive/2010/10/10/ado_1.html

三套路-----增删改

bubuko.com,布布扣
bubuko.com,布布扣
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();
bubuko.com,布布扣

三套路-----查(绑定到DataGridView

bubuko.com,布布扣
bubuko.com,布布扣
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]);
bubuko.com,布布扣

三套路----查(绑定到ListView)

bubuko.com,布布扣
bubuko.com,布布扣
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();
bubuko.com,布布扣

ADO.NET 增删查改小总结,布布扣,bubuko.com

ADO.NET 增删查改小总结

原文:http://www.cnblogs.com/cugwx/p/3586681.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!