Chili.Opf3 Send comments on this topic.
Commit Method
See Also  Example
Chili.Opf3 Namespace > ObjectContext Class : Commit Method




Commits the current transaction.

Syntax

Visual Basic (Declaration) 
Public Sub Commit() 
Visual Basic (Usage)Copy Code
Dim instance As ObjectContext
 
instance.Commit()
C# 
public void Commit()
Managed Extensions for C++ 
public: void Commit(); 
C++/CLI 
public:
void Commit(); 

Exceptions

ExceptionDescription
ExceptionNo transaction active.

Example

The following example shows how to use transaction management.
C#Copy Code
// Creates a new ObjectContext that uses an MsSql Server as storage. 
ObjectContext context = new ObjectContext(new MsSqlStorage("sa", "",  
    "localhost", "application")); 
  
// ... Other code. 
  
// Get an ObjectSet containing all user matching the name. 
// The result is sorted by Name. 
ObjectSet<User> objectSet = context.GetObjectSet<User> 
    ("Name like {0} SortBy Name Asc", "%mith%"); 
  
// Change all names of the user objects. 
foreach(User user in objectSet) 

    user.Name = "new Name"; 

  
// Starts a new Transaction. 
context.StartTransaction(); 
  
try 

    // Deletes the user object from the storage. 
    context.PersistChanges(objectSet); 
  
    // Commit the changes to the storage. 
    context.Commit(); 

catch (Exception ex) 

    // Rolls the changes back. 
    context.Rollback(); 
    Console.WriteLine("Error: " + ex.Message"); 

    

Remarks

Commits an open transaction on the connected IStorage. This routine is only supported if the storage implements also the ITransactionStorage interface. You don't get an exception if the storage does not support transactions and you call this routine.

Requirements

Platforms: Windows 2000, Windows XP family, Windows Server 2003 family, Windows Vista family

See Also