DataConnector | ComponentOne
ADO.NET provider for OData / Schema Details
In This Topic
    Schema Details
    In This Topic

    The ADO.NET provider for OData supports schema discovery using ADO.NET classes or SQL statements to the system tables. This is done through the GetSchema method of the C1ODataConnection class, optionally specifying schema name and restriction values.

    In the code example below, the GetSchema method is called firstly to return the Tables of the database, then called again to return the Columns of a specific datatable.

    C#
    Copy Code
    using (var connection = new C1ODataConnection(connstr))
    {
        connection.Open();
    
        // Get a list of tables
        DataTable databaseTables = connection.GetSchema("Tables");
        Console.WriteLine("List of Tables in database:\n");
        foreach (DataRow row in databaseTables.Rows)
        {
            // Print table names
            Console.WriteLine(row["TableName"]);
        }
    
        // Get column names in a table
        DataTable datatableColumns = connection.GetSchema("Columns", new string[] { "Products" });
        Console.WriteLine("\n Products table columns:");
        foreach (DataRow column in datatableColumns.Rows)
        {
            // Print column properties
            Console.Write(column["ColumnName"]);
            Console.Write("\t" + column["DataType"]);
            Console.Write("\t" + column["AllowDbNULL"] + "\n");
        }
    }

    Alternatively to the GetSchema method, the GetSchemaTable method of the C1DataReader class can be used, which returns a DataTable with the definitions of the column metadata.