Adding a New Object to a Collection

To add a new SQL-DMO object to a collection, you use the following steps:

  1. Create a new instance of a SQL-DMO object.
  2. Set the properties of the new SQL-DMO object.
  3. Add the new SQL-DMO object to the appropriate collection.

Adding a SQL-DMO object to a collection creates that SQL Server object.

Visual Basic

After creating a new SQL-DMO object with the New keyword of the Dim statement or the CreateObject function, you set the properties of the new object as appropriate for the new object. Then you add the new object to the appropriate collection using the following syntax:

Objects.Add NewObject

C++

After creating a new SQL-DMO object with the CoCreateInstance function, you set the properties of the new object as appropriate for the new object. Then you add the new object to the appropriate collection using the following syntax:

pObjects->Add ( pNewObject );

You can also use the AddObject "shortcut" function of the parent object to add the new object using the following syntax:

pParent->AddObject ( pNewObject );