IDbTableManager.GetTables Method

IIS 7.0

Returns a list of tables from a database.

Namespace:  Microsoft.Web.Management.DatabaseManager
Assembly:  Microsoft.Web.Management.DatabaseManager (in Microsoft.Web.Management.DatabaseManager.dll)

ICollection<Table> GetTables(
	string connectionString


Type: System.String
The connection string for the database.

Return Value

Type: System.Collections.Generic.ICollection<Table>
An ICollection object that contains the collection of Table objects.

All database providers that implement the IDbTableManager interface must also implement the GetTables method, which the database manager will use to retrieve the list of tables for a database.

The following code sample implements the GetTables method to retrieve the list of tables for an OLEDB connection by using the connection string that the database manager provides.

        // Retrieve the list of tables.
        public ICollection<Table> GetTables(string connectionString)
            List<Table> tables = new List<Table>();

            // Create a connection to the database.
            using (OleDbConnection connection = new OleDbConnection(connectionString))
                // Open the connection to the database.
                string[] restrictions = new string[4];
                restrictions[3] = "TABLE";

                // Open the schema information for the tables.
                DataTable schema = connection.GetSchema(OleDbMetaDataCollectionNames.Tables, restrictions);
                // Enumerate the list of tables.
                foreach (DataRow row in schema.Rows)
                    // Create a new table object.
                    Table table = new Table();
                    // Specify the table name.
                    table.Name = (string)row["TABLE_NAME"];
                    // Test for a creation date.
                    if (row["DATE_CREATED"] != DBNull.Value)
                        // Create a date/time object.
                        DateTime createDate = new DateTime();
                        // Parse the creation date for the table.
                        if (DateTime.TryParse(row["DATE_CREATED"].ToString(),out createDate))
                            // Specify the creation date for the table.
                            table.CreateDate = createDate;
                    // Specify the table schema.
                    table.Schema = (string)(row["TABLE_SCHEMA"] == DBNull.Value ? String.Empty : row["TABLE_SCHEMA"]);
                    // Add the table to the list of tables.
            // Return the list of tables.
            return tables;