Saving DataSets using Business Objects

MM .NET business objects have a set of SaveDataSet() methods that allow you to save DataSets to your back end data server.

Using SaveDataSet

The SaveDataSet() method is used to save the business object's DataSet and return one of the following mmSaveDataResult enumeration values:

  • RulesBroken = 1 (Business rules were broken - data is NOT saved)
  • RulesPassed = 2 (All Business rules passed - data is saved)
  • RuleWarnings = 3 (Warnings only - data is saved)
  • SaveCanceled = 4 (The Save was canceled)
  • Exception = 5 (An exception occurred when attempting to save)

For details, see Understanding Business Rule Objects

Example
Here is an example of code that calls SaveDataSet() .

In C#:

mmSaveDataResult result = employee.SaveDataSet();

In VB .NET:

Dim result As mmSaveDataResult = employee.SaveDataSet()

Saving Entities with Stored Procedures

Many developers prefer to save data by means of stored procedures (and other developers have no choice but to use them). One of the big reasons is that saving data using stored procedures can make your applications a bit faster. It also makes your application flexible because the data-specific SQL SELECT statements are stored in the database rather than in your program code! However, if your application needs to work with databases such as Microsoft Access that do not support stored procedures, you obviously need to avoid them!

If you want to use stored procedures to insert, update, and delete entities in your back end database, you can use the MM .NET Business Layer Generator to create a custom data access class that creates new stored procedures or uses existing stored procedures. For more information, under the topic Using the MM .NET Business Layer Generator, see the sub-topic Step 4: Data Access Layer Options.

Saving Entities with Dynamic SQL

If you do not create a custom data access class, by default MM .NET generates dynamic SQL statements to insert, update, and delete business entities from your back end database. It uses an ADO.NET CommandBuilder to generate these commands at run time.

Determining the Number of Rows Updated

The SaveDataSet() method saves the number of records updated in its RowsUpdatedOnSave property. You can reference this property after a successful save to determine how many rows were affected.

SaveDataSet Sequence

The following UML sequence diagram shows how the business object, business rule, and data access objects participate in the process of saving data in the SaveDataSet method:

There are four main things that happen in the SaveDataSet method:

  1. The business object raises a "Saving" state change event.

  2. The business object calls the rule object's CheckRules method, passing a reference to the current DataSet and table. The rule object checks all business rules and returns an mmSaveDataResult enumeration value indicating if there were broken rules or warnings.

  3. If there are no broken rules, the business object calls the data access object's SaveDataSet method, passing a reference to the DataSet.

  4. The business object raises the "Saved" state change event.


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 02/12/26
Comment or report problem with topic