DataTableReader.GetSchemaTable メソッド
アセンブリ: System.Data (system.data.dll 内)

Dim instance As DataTableReader Dim returnValue As DataTable returnValue = instance.GetSchemaTable
列メタデータを説明する DataTable。


GetSchemaTable メソッドは、各列のメタデータを次の順序で返します。
DataReader 列 | |
---|---|
ColumnName | 列が DataTable に表示されるときの名前。 |
ColumnOrdinal | 列の序数。 |
ColumnSize | DataColumn の ColumnSize (または MaxLength) プロパティが確認できない、または無関係な場合は -1。それ以外の場合は 0 または MaxLength 値を格納する正の整数値。 |
NumericPrecision | |
NumericScale | |
基になる列の型。 | |
ProviderType | 列のデータ型のインジケータ。行によって列のデータ型が異なる場合、この値は Object になります。この列に null 値を含めることはできません。 |
列のデータ型が String で、列の MaxLength プロパティが -1 の場合は、true。それ以外の場合は false。 | |
AllowDBNull | |
IsReadOnly | |
IsRowVersion | |
IsUnique | true の場合は、この列で同じ値を持つ 2 つの行は DataTable 内に存在しません。列自体がキーを表す場合、またはこの列にのみ適用される UNIQUE 型の制約がある場合、IsUnique は常に true になります。false の場合は、列には DataTable 内で重複している値を格納できます。この列の既定値は false です。 |
IsKey | true の場合は、列が DataTable の行を一意に識別するために組み合わされる、列のセットの 1 つであることを示します。IsKey が true に設定された列のセットは、DataTable 内の行を一意に識別する必要があります。この列のセットが列の最小セットである必要はありません。この列のセットは、DataTable の主キー、UNIQUE 制約、または一意のインデックスから生成されることもあります。false の場合は、列が、行を一意に識別する必要がないことを示します。列が単一の主キーまたは複合主キーに関与している場合、この値は true になります。それ以外の場合、値は false になります。 |
IsAutoIncrement | true の場合は、列が、新しい行に固定インクリメントで値を割り当てることを示します。false の場合は、列が、新しい行に固定インクリメントで値を割り当てないことを示します。この列の既定値は false です。 |
BaseCatalogName | この列を格納するデータ ストア内のカタログの名前。ベース カタログ名を確認できない場合は Null。この列の既定値は null 参照 (Visual Basic では Nothing) 値です。 |
BaseSchemaName | この値は常に Null です。 |
BaseTableName | DataTable の名前。 |
BaseColumnName | DataTable 内の列名。 |
AutoIncrementSeed | DataTable の .P:System.Data.DataColumn.AutoIncrementSeed プロパティの値。 |
AutoIncrementStep | DataTable の AutoIncrementStep プロパティの値。 |
DataColumn の DefaultValue プロパティの値。 | |
現在の列が式列であり、式で使用されているすべての列が、その式列を格納している T:System.Data.DataTable に属している場合、これは式の文字列になります。それ以外の場合は null 参照 (Visual Basic では Nothing)。 | |
ColumnMapping | DataColumn に関連付けられた MappingType 値。Attribute、Element、Hidden、SimpleContent のいずれかの値になります。既定値は Element です。 |
BaseTableNamespace | |
BaseColumnNamespace |

指定した列のスキーマ情報を取得するコンソール アプリケーションの例を次に示します。DisplaySchemaTableInfo プロシージャに DataTableReader を渡し、さらに DataTableReader 内の列の序数位置を表す整数値を渡します。プロシージャはコンソール ウィンドウにスキーマ情報を出力します。
Private Sub TestGetSchemaTable() ' Set up the data adapter, using information from ' the AdventureWorks sample database. ' Modify the SQL expression to retrieve ' data from a different table. Dim adapter As SqlDataAdapter = _ SetupDataAdapter("SELECT * FROM Sales.Customer") ' Fill the DataTable, retrieving all the schema information. adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey Dim table As New DataTable adapter.Fill(table) ' Create the DataTableReader, and close it when done. Using reader As New DataTableReader(table) ' Modify the column number to display information ' about a column other than column 0. DisplaySchemaTableInfo(reader, 0) End Using Console.WriteLine() Console.WriteLine("Press Enter to finish.") Console.ReadLine() End Sub Private Sub DisplaySchemaTableInfo( _ ByVal reader As DataTableReader, ByVal ordinal As Integer) ' Given a DataTableReader, display schema ' information about a particular column. Try Dim schemaTable As DataTable = reader.GetSchemaTable() Dim row As DataRow = schemaTable.Rows(ordinal) For Each col As DataColumn In schemaTable.Columns Console.WriteLine("{0}: {1}", _ col.ColumnName, row(col.Ordinal)) Next Catch ex As IndexOutOfRangeException Console.WriteLine("{0} is an invalid column number.", _ ordinal) End Try End Sub Private Function SetupDataAdapter( _ ByVal sqlString As String) As SqlDataAdapter ' Assuming all the default settings, create a SqlDataAdapter ' working with the AdventureWorks sample database that's ' available with SQL Server. Dim connectionString As String = _ "Data Source=(local);" & _ "Initial Catalog=AdventureWorks;" & _ "Integrated Security=true" Return New SqlDataAdapter(sqlString, connectionString) End Function
private static void TestGetSchemaTable() { // Set up the data adapter, using information from // the AdventureWorks sample database. // Modify the SQL expression to retrieve // data from a different table. SqlDataAdapter adapter = SetupDataAdapter("SELECT * FROM Sales.Customer"); // Fill the DataTable, retrieving all the schema information. adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; DataTable table = new DataTable(); adapter.Fill(table); // Create the DataTableReader, and close it when done. using (DataTableReader reader = new DataTableReader(table)) { // Modify the column number to display information // about a column other than column 0. DisplaySchemaTableInfo(reader, 0); } Console.WriteLine(); Console.WriteLine("Press Enter to finish."); Console.ReadLine(); } private static void DisplaySchemaTableInfo( DataTableReader reader, int ordinal) { // Given a DataTableReader, display schema // information about a particular column. try { DataTable schemaTable = reader.GetSchemaTable(); DataRow row = schemaTable.Rows[ordinal]; foreach (DataColumn col in schemaTable.Columns) { Console.WriteLine("{0}: {1}", col.ColumnName, row[col.Ordinal]); } } catch (IndexOutOfRangeException ex) { Console.WriteLine("{0} is an invalid column number.", ordinal); } } private static SqlDataAdapter SetupDataAdapter(String sqlString) { // Assuming all the default settings, create a // SqlDataAdapter working with the AdventureWorks // sample database that's available with // SQL Server. String connectionString = "Data source=(local);initial catalog=AdventureWorks;" + "Integrated Security=True"; return new SqlDataAdapter(sqlString, connectionString); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDataTableReader.GetSchemaTable メソッドを検索する場合は、下記のリンクをクリックしてください。

- DataTableReader.GetSchemaTable メソッドのページへのリンク