The ADO.NET provider for ServiceNow supports schema discovery using ADO.NET classes or SQL statements to the system tables. The GetSchema method can be used to retrieve 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# |
コードのコピー
|
---|---|
static void SchemaDetails() { //接続を作成して開きます。 C1ServiceNowConnection conn = new C1ServiceNowConnection(connectionString); conn.Open(); //スキーマの詳細を取得: //テーブル名を取得します。 DataTable databaseTables = conn.GetSchema("Tables"); Console.WriteLine("List of Tables in database: \n"); foreach (DataRow row in databaseTables.Rows) { //テーブル名を表示します。 string tableName = row["TableName"].ToString(); Console.WriteLine(tableName); } //テーブル内の列名を取得します。 Console.WriteLine("Columns in table incident: \n"); DataTable dtColumnsSchema = conn.GetSchema("Columns", new string[] { tableName }); foreach (DataRow crow in dtColumnsSchema.Rows) { Console.WriteLine(crow["ColumnName"].ToString() + "\t" + crow["DataType"].ToString()); } //接続を切ります。 conn.Close(); } |
Alternatively 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.