# IDataSource.Add()

Description:

The `Add` method creates a new calendar on the device or adds an entry to a calendar. In the latter case, if an entry with the same `LocalId` already exists in the calendar, it is modified accordingly. You can thus use this method to both add and update calendar entries. The entry is added to the specified calendar or, if no calendar is specified, to the default one. If the default calendar does not exist, it is created.

This is a synchronous method.

Syntax:

    result = so.IDataSource.Add(criteria);

Arguments:

- `criteria`:

  This is an object that specifies the calendar to create or the calendar entry to add or update. For more information about the object properties and how to define them, see section Criteria for adding and updating calendar information.

Return value:

The `Add` method returns an object that contains an error code and an error message. In addition, if a calendar entry was added or updated, the result object contains the `id` of that entry.

Table: Return value properties for Add
Property | Description | Value
--- | --- | ---
`[result.ReturnValue]` | This is a text string that contains the `id` of the entry that was added or updated. If a new calendar was created, this property is not included in the result object. |
`result.ErrorCode` | This is a number that specifies a predefined error code. | See Service API error codes.
`result.ErrorMessage` | This is a text string that describes the error. | See Calendar Service API error messages.

Remarks:

- If an entry is added or updated to a calendar other than the default one, the corresponding calendar file must exist on the device.

- For detailed information about calendar entries, see section Calendar entries.

Example code:

For the complete source of a sample widget that demonstrates how to use this Service API, see the full example.