Collection Methods

SQL-DMO

SQL-DMO

Collection Methods

All collections support some form of the Item method. As its name implies, the Item method is used to dereference a collection member. For most collections, SQL-DMO supports the ItemByName and ItemByOrd methods.

With the ItemByName method, you can refer to a specific member using its name. This Microsoft® Visual Basic® example shows selecting a database by name:

Dim oDatabase as SQLDMO.Database
Set oDatabase = oSQLServer.Databases("Northwind")

With the ItemByOrd method, you can refer to a specific member by its ordinal location within the collection. This Visual Basic example shows setting a combo box to list the databases on a server:

Dim nDatabase as Integer
For nDatabase = 1 to oSQLServer.Databases.Count
    Combo1.AddItem oSQLServer.Databases(nDatabase).Name
Next nDatabase

Note  For more information about specific collection support for ItemByName and ItemByOrd, see Collections.

Most collections expose the Add and Remove methods. The Add method forms part of the SQL-DMO three-step process for creating Microsoft SQL Server™ components. The Remove method drops or deletes a SQL Server component.

Some collections expose other methods. For example, the TransPublications collection supports the Script method. When invoked on the collection, the Script method generates a single Transact-SQL script that could be used to re-create all transaction replication publications defined for a SQL Server database.