DataTableReader.GetSchemaTable メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataTableReader.GetSchemaTable メソッドの意味・解説 

DataTableReader.GetSchemaTable メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

DataTableReader の列メタデータ記述する DataTable を返します

名前空間: System.Data
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Overrides Function
 GetSchemaTable As DataTable
Dim instance As DataTableReader
Dim returnValue As DataTable

returnValue = instance.GetSchemaTable
public override DataTable GetSchemaTable ()
public:
virtual DataTable^ GetSchemaTable () override
public DataTable GetSchemaTable ()
public override function GetSchemaTable ()
 : DataTable

戻り値
メタデータ説明する DataTable

例外例外
例外種類条件

InvalidOperationException

DataTableReader閉じてます。

解説解説

GetSchemaTable メソッドは、各列のメタデータ次の順序返します

DataReader 列

説明

ColumnName

列が DataTable表示されるときの名前。

ColumnOrdinal

列の序数

ColumnSize

DataColumn の ColumnSize (または MaxLength) プロパティ確認できない、または無関係な場合は -1。それ以外場合は 0 または MaxLength 値を格納する正の整数値。

NumericPrecision

列の型が数値型場合は、列の最大精度なります。列の型が数値データ型ではない場合null 値です。

NumericScale

列のデータ型小数点以下の部分がある場合小数点右側桁数返しますそれ以外場合は、null 値返します

DataType

基になる列の型。

ProviderType

列のデータ型インジケータ。行によって列のデータ型異な場合、この値は Objectなります。この列に null 値含めることはできません。

IsLong

列のデータ型String で、列の MaxLength プロパティが -1 の場合は、trueそれ以外場合false

AllowDBNull

列の AllowDbNull 制約true設定されている場合は、trueそれ以外場合false

IsReadOnly

列を変更できない場合trueそれ以外場合false

IsRowVersion

すべての列で false

IsUnique

true場合は、この列で同じ値を持つ 2 つの行は DataTable 内に存在しません。列自体キーを表す場合、またはこの列にのみ適用される UNIQUE 型の制約がある場合IsUnique は常に trueなりますfalse場合は、列には DataTable 内で重複している値を格納できます。この列の既定値false です。

IsKey

true場合は、列が DataTable の行を一意識別するために組み合わされる、列のセット1 つであることを示しますIsKeytrue設定された列のセットは、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 プロパティの値。

DefaultValue

DataColumnDefaultValue プロパティの値。

Expression

現在の列が式列であり、式で使用されているすべての列が、その式列を格納している T:System.Data.DataTable属している場合、これは式の文字列なりますそれ以外場合null 参照 (Visual Basic では Nothing)。

ColumnMapping

DataColumn関連付けられた MappingType 値。AttributeElementHiddenSimpleContentいずれかの値になります既定値Element です。

BaseTableNamespace

DataTableNamespace プロパティの値。

BaseColumnNamespace

DataColumnNameSpace プロパティの値。

使用例使用例

指定した列のスキーマ情報取得するコンソール アプリケーションの例を次に示します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);
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

DataTableReader.GetSchemaTable メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataTableReader.GetSchemaTable メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS