update 方法确实允许您在 tableAdapter 中插入、更新或删除更改。MSDN:'当您的应用程序使用数据集存储数据时,请使用 TableAdapter.Update 方法。Update 方法将所有更改(更新、插入和删除)发送到数据库'。尽管如果您想对数据插入进行更多控制,但不允许您传递数据行,但必须使用参数来代替使用 Insert。请参阅 MSDN 上的完整参考:http: //msdn.microsoft.com/en-us/library/ms233812 (v=vs.110).aspx
更新方法使用的代码示例。
// Create a new row.
NorthwindDataSet.RegionRow newRegionRow;
newRegionRow = northwindDataSet.Region.NewRegionRow();
newRegionRow.RegionID = 5;
newRegionRow.RegionDescription = "NorthWestern";
// Add the row to the Region table
this.northwindDataSet.Region.Rows.Add(newRegionRow);
// Save the new row to the database
this.regionTableAdapter.Update(this.northwindDataSet.Region);
代码示例插入:
NorthwindDataSetTableAdapters.RegionTableAdapter regionTableAdapter =
new NorthwindDataSetTableAdapters.RegionTableAdapter();
regionTableAdapter.Insert(5, "NorthWestern");