DataConnector | ComponentOne
ADO.NET provider for Dynamics 365 Sales / Schema Details
In This Topic
    Schema Details
    In This Topic

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

    In the following code, the GetSchema method is first called to return the Tables of the database, and then it is called again to return the columns of a specific datatable.

    C#
    Copy Code
    static void ReadSchema()
    {
        using (var connection = new C1D365SConnection(connectionString))
        {
            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[] { "Accounts" });
            Console.WriteLine("\n Accounts table columns:");
            Console.WriteLine(String.Format("{0}\t\t\t\t {1}", "Column Name", "DataType"));
            foreach (DataRow column in datatableColumns.Rows)
            {
                // Print column properties
                Console.WriteLine(String.Format("{0}\t\t\t\t {1}", column["ColumnName"], column["DataType"]));
            }
        }
    }

    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.