Skip to content

Add

Appends a new row to the table and returns the new row.

1
myDataTable.Add(row: object):DataRow

Appends a new row to the table, calls the function with the row as this, and returns the new row.

1
myDataTable.Add(fn: (this: DataRow) => void):DataRow

Parameters

object row
    An object containing the column values for the new row.

(this: DataRow) => void fn
    A function that sets the row values.

Returns

A DataRow object representing the newly added row.

Remarks

Properties are matched to columns by name, case-insensitively; properties without a matching column are ignored. The row is inserted when DataTable.Save is called.

Examples

Add a row from an object

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
var groups = $Database.Empty({
    TargetSchema : 'HR',
    TargetTable : 'Groups'
});

groups.Add({
    Id : NewId(),
    Name : 'Reviewers'
});

groups.Save();

Add a row with a function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
var groups = $Database.Empty({
    TargetSchema : 'HR',
    TargetTable : 'Groups'
});

groups.Add(function () {
    this.Id = NewId();
    this.Name = $Xml.Evaluate('GroupName');
});

groups.Save();

See Also