首先、你的datatable 的表结构必须与数据库中你要更新的表的结构一致。

用到 SqlCommandBuilder 实现批量更新.

SqlConnection  conn = new SqlConnection('连接字符串'));
        
     SqlDataAdapter myAdapter = new SqlDataAdapter();
     SqlCommand myCommand = new SqlCommand("select * from "+表名称),(SqlConnection) conn);   
     myAdapter.SelectCommand = myCommand;
     SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);    
  try

      {    myAdapter.Update(ds,strTblName);  }  

catch{}

相关文章: