次の方法で共有


DataSet.AcceptChanges メソッド

この DataSet の読み込み、または前回の AcceptChanges の呼び出し以降にこのデータセットに対して行われたすべての変更をコミットします。

Public Sub AcceptChanges()
[C#]
public void AcceptChanges();
[C++]
public: void AcceptChanges();
[JScript]
public function AcceptChanges();

解説

DataRow クラスと DataTable クラスの両方にも、 AcceptChanges メソッドが含まれています。 AcceptChangesDataTable レベルで呼び出すと、各 DataRowAcceptChanges メソッドが呼び出されます。同様に、 DataSetAcceptChanges を呼び出すと、 DataSet 内の各テーブルで AcceptChanges が呼び出されます。このように、このメソッドを複数のレベルで呼び出すことができます。 DataSetAcceptChanges を呼び出すと、1 回の呼び出しで、すべての従属オブジェクト (テーブル、行など) でこのメソッドを呼び出すことができます。

DataSetAcceptChanges を呼び出すと、編集モードの DataRow オブジェクトは、正常に編集を終了します。各 DataRowRowState プロパティも変更されます。 Added および Modified の行は Unchanged になり、 Deleted の行は削除されます。

DataSetForeignKeyConstraint オブジェクトが格納されている場合は、 AcceptChanges メソッドを呼び出すと、 AcceptRejectRule も適用されます。

使用例

[Visual Basic, C#, C++] DataRowDataSet 内の DataTable に追加する例を次に示します。次に、 DataSetAcceptChanges メソッドを呼び出して、データセットに含まれるすべての DataTable オブジェクトに対して連鎖操作を実行します。

 
Private Sub AcceptChanges()
   Dim myDataSet As DataSet
   myDataSet = new DataSet()

   ' Not shown: methods to fill the DataSet with data.
   Dim t As DataTable

   t = myDataSet.Tables("Suppliers")

   ' Add a DataRow to a table.
   Dim myRow As DataRow
   myRow = t.NewRow()
   myRow("CompanyID") = "NWTRADECO"
   myRow("CompanyName") = "NortWest Trade Company"

   ' Add the row.
   t.Rows.Add( myRow )

   ' Calling AcceptChanges on the DataSet causes AcceptChanges to be
   ' called on all subordinate objects.
   myDataSet.AcceptChanges()
End Sub

[C#] 
private void AcceptChanges()
{
   DataSet myDataSet;
   myDataSet = new DataSet();

   // Not shown: methods to fill the DataSet with data.
   DataTable t;
   t = myDataSet.Tables["Suppliers"];

   // Add a DataRow to a table.
   DataRow myRow;
   myRow = t.NewRow();
   myRow["CompanyID"] = "NWTRADECO";
   myRow["CompanyName"] = "NortWest Trade Company";

   // Add the row.
   t.Rows.Add( myRow );

   // Calling AcceptChanges on the DataSet causes AcceptChanges to be
   // called on all subordinate objects.
   myDataSet.AcceptChanges();
}

[C++] 
private:
void AcceptChanges()
{
   DataSet* myDataSet;
   myDataSet = new DataSet();

   // Not shown: methods to fill the DataSet with data.
   DataTable* t;
   t = myDataSet->Tables->Item[S"Suppliers"];

   // Add a DataRow to a table.
   DataRow* myRow;
   myRow = t->NewRow();
   myRow->Item[S"CompanyID"] = S"NWTRADECO";
   myRow->Item[S"CompanyName"] = S"NortWest Trade Company";

   // Add the row.
   t->Rows->Add( myRow );

   // Calling AcceptChanges on the DataSet causes AcceptChanges to be
   // called on all subordinate objects.
   myDataSet->AcceptChanges();
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

DataSet クラス | DataSet メンバ | System.Data 名前空間 | AcceptChanges | AcceptRejectRule | BeginEdit | DataRow | ForeignKeyConstraint