DataTable.acceptchange

xiaoxiao2021-03-06  20

Submit all changes to the table since the last call AcceptChanges.

[Visual Basic]

Public sub acceptchanges ()

[C #]

Public void acceptchanges ();

[C ]

PUBLIC: Void Acceptchanges ();

[Jscript]

Public Function Acceptchanges ();

Note

When calling acceptchanges, any DataRow object that is still editing mode will successfully end its editing. DataRowState also changes: all status of all status of ADDED and MODIFIEDs becomes unchanged; status is removed from DELETED.

After you try to update the DataSet after you try to update the DataSet, you usually call the ACCEPTCHANGES method to the DataTable.

Example

[Visual Basic, C #, C ] The following example tests if there is an error in each table. If the error in the table can be coordinated (by passing it to an undefined function), acceptChange is called; otherwise calls REJECTCHANGES.

[Visual Basic]

Private sub acceptorreject (MyTable as dataable)

'Ness there are errors, try to reconcile.

IF (not myTable.haserror)

IF (Reconcile (MyTable))

'Fixed All Errors.

MyTable.acceptchange

Else

'Couldn't fix all errors.

MyTable.rejectchange

END IF

Else

'If no errors, acceptchanges.

MyTable.acceptchange ()

END IF

End Sub

Private function reconcile (thisTable as datatable) as boolean

Dim Myrow As DataRow

For Each Myrow in thisTable.Rows

'INSERT CODE to try to reconcile error.

'If there is stores ERRORS RETURN IMMEDIATELY

'Since The Caller Rejects All Changes Upon Error.

Ifmow.haserrors the

Reconcile = false

EXIT FUNCTION

END IF

Next Myrow

Reconcile = TRUE

END FUNCTION

[C #]

Private Void Acceptorreject (DataTable MyTable)

{

// if there is the error.

IF (! myTable.haserrors)

{

IF (Reconcile (MyTable))

{

// Fixed All Errors.

MyTable.acceptchanges ();

}

Else

{

// couldn't fix all errors.

MyTable.rejectchanges ();

}

}

Else

// if no errors, acceptchange.

MyTable.acceptchanges ();

}

Private bool reconcile (DataTable thisTable)

{

Foreach (DataRow Myrow In thisTable.Row)

{

// INSERT CODE to try to reconcile error.

// if there is still error Errors Return Immediately

// Since The Caller Rejects All Changes Upon Error.

IF (Myrow.haserRRORS)

Return False;

}

Return True;

}

[C ]

Private:

Void Acceptorreject (DataTable * MyTable)

{

// if there is the error.

IF (! myTable-> Haserror)

{

IF (Reconcile (MyTable))

{

// Fixed All Errors.

Mytable-> acceptchanges ();

}

Else

{

// couldn't fix all errors.

MyTable-> Rejectchanges ();

}

}

Else

// if no errors, acceptchange.

Mytable-> acceptchanges ();

}

Bool Reconcile (DataTable * thisTable)

{

System :: Collections :: ienumerator * myenum = thisTable-> rows-> getenumerator ();

While (MyEnum-> MoveNext ())

{

DATAROW * Myrow = __TRY_CAST (MyEnum-> Current);

// INSERT CODE to try to reconcile error.

// if there is still error Errors Return Immediately

// Since The Caller Rejects All Changes Upon Error.

IF (MyRow-> Haserror)

Return False;

}

Return True;

}

[JScript] There is no example available for JScript. To view Visual Basic, C # or C examples, click the "Language Filter" button in the upper left corner.

Claim

Platform: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 Series, .NET Framework Lite

See

DataTable Class | DataTable Member | System.Data Name Space | AcceptChanges | Beginedit | DataRowState | Endedit | Rejectchanges

转载请注明原文地址:https://www.9cbs.com/read-42842.html

New Post(0)