作用:c#中用來批量更新數(shù)據(jù)庫
  用法:一般和adapter結(jié)合使用。
  例:
  SqlConnection conn = new SqlConnection(strConnection));//連接數(shù)據(jù)庫
  DataSet ds=new DataSet();
  SqlDataAdapter myAdapter = new SqlDataAdapter();//new一個adapter對象
  adapter.SelectCommand = new SqlCommand("select * from "+strTblName),(SqlConnection) conn); //cmd
  SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter); //new 一個 SqlCommandBuilder
  myAdapter.Fill(ds);
  myAdapter.InsertCommand = myCommandBuilder .GetInsertCommand();//插入
  myAdapter.UpdateCommand = myCommandBuilder .GetUpdateCommand();//更新
  myAdapter.DeleteCommand = myCommandBuilder .GetDeleteCommand();//刪除
  conn.Open();//打開數(shù)據(jù)庫
  myAdapter.Update(ds); //更新ds到數(shù)據(jù)庫
  conn.Close();//關閉數(shù)據(jù)庫
  何時使用:
  a. 有時候需要緩存的時候,比如說在一個商品選擇界面,選擇好商品,并且進行編輯/刪除/更新后,
  最后一并交給數(shù)據(jù)庫,而不是每一步操作都訪問數(shù)據(jù)庫,因為客戶選擇商品可能進行n次編輯/刪除
  更新操作,如果每次都提交,不但容易引起數(shù)據(jù)庫沖突,引發(fā)錯誤,而且當數(shù)據(jù)量很大時在用戶執(zhí)行
  效率上也變得有些慢
  b.有的界面是這樣的有的界面是這樣的,需求要求一定用緩存實現(xiàn),確認之前的操作不提交到庫,點擊
  頁面專門提交的按鈕時才提交商品選擇信息和商品的其它信息. 我經(jīng)常遇到這樣的情況
  c.有些情況下只往數(shù)據(jù)庫里更新,不讀取. 也就是說沒有從數(shù)據(jù)庫里讀,SqlDataAdapter也就不知道是
  更新哪張表了,調(diào)用Update就很可能出錯了。這樣的情況下可以用SqlCommandBuilder 了
 ?。ù硕螀⒖剂怂怂鳎?
  d.在使用adapter的時候如果不是用設計器的時候,并且要用到adapter.Update()函數(shù)的時候,這時候要注意
  SqlCommandBuilder必須要有
  常見錯誤:
  一些初學者經(jīng)常會在使用adapter的時候忘了使用SqlCommandBuilder,即使用了也會忘了用
  myAdapter.UpdateCommand = myCommandBuilder .GetUpdateCommand();//更新,
  還自以為是很對,感覺煩躁不可救藥。
  摘自msdn
  The following example uses the derived class, OleDbDataAdapter, to update the data source.
  C#
  public DataSet CreateCmdsAndUpdate(string connectionString, string queryString)
  {
  using (OleDbConnection connection = new OleDbConnection(connectionString))
  {
  OleDbDataAdapter adapter = new OleDbDataAdapter();
  adapter.SelectCommand = new OleDbCommand(queryString, connection);
  OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
  connection.Open();
  DataSet customers = new DataSet();
  adapter.Fill(customers);
  //code to modify data in dataset here
  adapter.Update(customers);
  return customers;
  }
  }