首页 应用 游戏 资讯 攻略

ADO.NET增删查改小总结

时间:2011-06-23 关注公众号 来源:网络

  三套路-----增删改

  Code

  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

  Code

  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();

阅读全文
扫码关注“ 多特资源库
更多更全的软件资源下载
文章内容来源于网络,不代表本站立场,若侵犯到您的权益,可联系我们删除。(本站为非盈利性质网站)
玩家热搜

相关攻略

正在加载中
版权
版权说明

文章内容来源于网络,不代表本站立场,若侵犯到您的权益,可联系我们删除。(本站为非盈利性质网站)

电话:13918309914

QQ:1967830372

邮箱:rjfawu@163.com

toast