DataSet.AcceptChanges メソッド
この DataSet の読み込み、または前回の AcceptChanges の呼び出し以降にこのデータセットに対して行われたすべての変更をコミットします。
Public Sub AcceptChanges()
[C#]
public void AcceptChanges();
[C++]
public: void AcceptChanges();
[JScript]
public function AcceptChanges();
解説
DataRow クラスと DataTable クラスの両方にも、 AcceptChanges メソッドが含まれています。 AcceptChanges を DataTable レベルで呼び出すと、各 DataRow の AcceptChanges メソッドが呼び出されます。同様に、 DataSet で AcceptChanges を呼び出すと、 DataSet 内の各テーブルで AcceptChanges が呼び出されます。このように、このメソッドを複数のレベルで呼び出すことができます。 DataSet の AcceptChanges を呼び出すと、1 回の呼び出しで、すべての従属オブジェクト (テーブル、行など) でこのメソッドを呼び出すことができます。
DataSet で AcceptChanges を呼び出すと、編集モードの DataRow オブジェクトは、正常に編集を終了します。各 DataRow の RowState プロパティも変更されます。 Added および Modified の行は Unchanged になり、 Deleted の行は削除されます。
DataSet に ForeignKeyConstraint オブジェクトが格納されている場合は、 AcceptChanges メソッドを呼び出すと、 AcceptRejectRule も適用されます。
使用例
[Visual Basic, C#, C++] DataRow を DataSet 内の DataTable に追加する例を次に示します。次に、 DataSet で AcceptChanges メソッドを呼び出して、データセットに含まれるすべての 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