The ADO.NET provider for Kintone supports schema discovery using ADO.NET classes or SQL statements to the system tables. This is done through the GetSchema method of the C1KintoneConnection class, which optionally specify the schema name and restriction values.
In the following code example , the GetSchema method is called to returns the tables in the database. In the second call, the method returns the columns in a specific data table.
C# |
コードのコピー
|
---|---|
static void SchemaDetails() { const string Username = "*******"; const string Password = "*********"; const string Url = "https://xg0w2.kintone.com"; string kintoneConnection = string.Format("Username={0};Password={1};Url={2}", Username, Password, Url); using (C1KintoneConnection connection = new C1KintoneConnection(kintoneConnection)) { connection.Open(); //テーブルのリストを取得します。 DataTable databaseTables = connection.GetSchema("Tables"); Console.WriteLine("List of Tables in database:"); foreach (DataRow row in databaseTables.Rows) { //テーブル名を表示します。 Console.WriteLine(row["TableName"]); } //テーブル内の列名を取得します。 DataTable datatableColumns = connection.GetSchema("Columns", new string[] { "Products" }); Console.WriteLine("\n Products Table columns:"); foreach (DataRow column in datatableColumns.Rows) { //列のプロパティを表示します。 Console.Write(column["ColumnName"]); Console.Write("\t" + column["DataType"]); } } } |
Alternatively to the GetSchema method, you can also use the GetSchemaTable method of the C1DataReader class which returns a DataTable with the definition of the column metadata.