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

    The ADO.NET provider for Snowflake supports schema discovery using ADO.NET classes or SQL statements to the system tables. The GetSchema method can be used to retrieve the schema of the Database and DataTables. 

     

    The following code shows how the GetSchema method is called which returns Tables in the Database. In the second call, the method returns the columns of a specific data table.

    C#
    Copy Code
    static void SchemaDetails()
    {
        //Create and open connection
        C1SnowflakeConnection conn = new C1SnowflakeConnection(connectionString);
        conn.Open();
        //Get Schema Details:
        //Get table names
        DataTable databaseTables = conn.GetSchema("Tables");
        Console.WriteLine("List of Tables in database: \n");
        foreach (DataRow row in databaseTables.Rows)
        {
            //Display table names
            string tableName = row["TableName"].ToString();
            Console.WriteLine(tableName);
        }
        //Get column names in a table
        Console.WriteLine("Columns in table CALL_CENTER: \n");
        DataTable dtColumnsSchema = conn.GetSchema("Columns", new string[] { "CALL_CENTER" });
        foreach (DataRow crow in dtColumnsSchema.Rows)
        {
            Console.WriteLine(crow["ColumnName"].ToString() + "\t" + crow["DataType"].ToString());
        }
        //Close Connection
        conn.Close();
    }

    Similar to the GetSchema method, you can also use GetSchemaTable method of the C1DataReader class. The GetSchemaTable method returns a DataTable that defines the column metadata.