熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ADO.NET增刪查改小總結

2022-06-13   來源: .NET編程 

  三套路增刪改

  Code

   using SystemDataSqlClient;

  

               SqlConnection conn = new SqlConnection(xxx);

  

  

               string sql = xxx;

  

               SqlCommand comm = new SqlCommand(sql conn);

  

               connOpen();

  

               commExecuteNonQuery();

  

               connClose();

  三套路查(綁定到DataGridView

  Code

   using SystemDataSqlClient;

  

               SqlConnection conn = new SqlConnection(xxx);

  

               string sql = xxx;

  

               SqlDataAdapter da = new SqlDataAdapter(sql conn);

  

               DataSet ds = new DataSet();

  

               daFill(ds);

  

               dataGridViewDataSource = dsTables[];

  

     //要更新 查詢語句要 查詢主鍵列

  

               SqlCommandBuilder sd = new SqlCommandBuilder(da);

  

               daUpdate(dsTables[]);

  三套路查(綁定到ListView)

  代碼

  using SystemDataSqlClient;

  SqlConnection conn = new SqlConnection(xxx);

  string sql = xx;

  SqlCommand comm = new SqlCommand(sql conn);

  connOpen();

  SqlDataReader read = commExecuteReader();

  while (readRead())

  {

  ListViewItem lvi = new ListViewItem(read[xxx]ToString());

  lviTag = read[id];

  listViewItemsAdd(lvi);

  lviSubItemsAddRange(new String[] { read[xxx]ToString() });

  }

  readClose();

  connClose();


From:http://tw.wingwit.com/Article/program/net/201311/13294.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.