VistaDB 6
VistaDB / Developer's Guide / SQL Reference / Database Schema / VistaDBConnection GetSchema Examples
In This Topic
    VistaDBConnection GetSchema Examples
    In This Topic

    There are several ways to get the schema from a database. The VistaDBConnection.GetSchema is one of the best starting points to determine what you need to drill down into for more information.

    See the complete MSDN Article on working with GetSchema calls.

    The default call gives you a list of all the types of schema collections you can request, and how many restrictions they require. Drill down with calls to the GetSchema with the specific collection name, and restrictions for more detailed information (like FOREIGNKEYS, VIEWS, etc).

    Example

    GetSchema Example
    Copy Code
    using( VistaDB.Provider.VistaDBConnection connection =
           new VistaDB.Provider.VistaDBConnection("Data Source=" + dbName) )
       {
          connection.Open();
          DataTable schema = connection.GetSchema();
          foreach (DataRow myField in schema.Rows)
          {
            foreach (DataColumn myProperty in schema.Columns)
            {
              System.Diagnostics.Debug.WriteLine(myProperty.ColumnName +
                 " = " + myField[myProperty].ToString());
            }
          }
       }
    

    Schema Collection Types

    Some of the collection types you can ask for are:

    DATATYPES
    COLUMNS
    INDEXES
    INDEXCOLUMNS
    TABLES
    FOREIGNKEYS
    FOREIGNKEYCOLUMNS
    RESERVEDWORDS
    VIEWS
    VIEWCOLUMNS
    PROCEDURES
    PROCEDUREPARAMETERS
    RESTRICTIONS

    We have created an enum of these constant values for you to use in your code (rather than using the text).

    VistaDBConnection.SchemaConstants contains all the valid collections you may request from GetSchema.

    In your code you would use something like this:

    DataTable schema = connection.GetSchema("COLUMNS"); // These two lines are the same DataTable schema = connection.GetSchema( VistaDBConnection.SchemaConstants.SCHEMA_COLUMNS );

    That would pull all the schema_columns information with no restrictions.

    See Also