SqlCommandBuilder

 

 作用:c#中用来批量更新数据库

  用法:一般和adapter结合使用。

  例:

  SqlConnection conn = new SqlConnection(strConnection));//连接数据库

  SqlDataAdapter myAdapter = new SqlDataAdapter();//new一个adapter对象

  adapter.SelectCommand = new SqlCommand("select * from "+strTblName),(SqlConnection) conn); //cmd

  SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter); //new 一个 SqlCommandBuilder

  myAdapter.InsertCommand = myCommandBuilder .GetInsertCommand();//插入

  myAdapter.UpdateCommand = myCommandBuilder .GetUpdateCommand();//更新

  myAdapter.DeleteCommand = myCommandBuilder .GetDeleteCommand();//删除

  conn.Open();//打开数据库

  myAdapter.Update(ds); //更新ds到数据库

  conn.Close();//关闭数据库

  

你可能感兴趣的:(SqlCommandBuilder)