DataTable.PrimaryKey プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataTable.PrimaryKey プロパティの意味・解説 

DataTable.PrimaryKey プロパティ

このデータ テーブル主キーとして機能する列の配列取得または設定します

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

Dim instance As DataTable
Dim value As DataColumn()

value = instance.PrimaryKey

instance.PrimaryKey = value
public DataColumn[] PrimaryKey { get; set;
 }
public:
property array<DataColumn^>^ PrimaryKey {
    array<DataColumn^>^ get ();
    void set (array<DataColumn^>^ value);
}
/** @property */
public DataColumn[] get_PrimaryKey ()

/** @property */
public void set_PrimaryKey (DataColumn[] value)

プロパティ
DataColumn オブジェクト配列

例外例外
例外種類条件

DataException

キー外部キーです。

解説解説
使用例使用例

DataGrid に表示される DataTable の主キー列を返す方法次の例に示します2 番目の例は、DataTable主キー列の設定方法示します

Private Sub GetPrimaryKeys(table As
 DataTable)
   ' Create the array for the columns.
   Dim columns() As DataColumn 
   columns = table.PrimaryKey

   ' Get the number of elements in the array.
   Console.WriteLine("Column Count: " & columns.Length.ToString())
   Dim i As Integer
   For i = 0 To columns.GetUpperBound(0)
      Console.WriteLine(columns(i).ColumnName & columns(i).DataType.ToString())
   Next i
End Sub

Private Sub SetPrimaryKeys()
   ' Create a new DataTable and set two DataColumn objects as primary
 keys.
   Dim table As DataTable = new
 DataTable()
   Dim keys(2) As DataColumn
   Dim column  As DataColumn

   ' Create column 1.
   column = New DataColumn()
   column.DataType = System.Type.GetType("System.String")
   column.ColumnName= "FirstName"

   ' Add the column to the DataTable.Columns collection.
   table.Columns.Add(column)
   ' Add the column to the array.
   keys(0) = column

   ' Create column 2 and add it to the array.
   column = New DataColumn()
   column.DataType = System.Type.GetType("System.String")
   column.ColumnName = "LastName"
   table.Columns.Add(column)

   ' Add the column to the array.
   keys(1) = column

   ' Set the PrimaryKeys property to the array.
   table.PrimaryKey = keys
End Sub
private void GetPrimaryKeys(DataTable table)
{
    // Create the array for the columns.
    DataColumn[] columns;
    columns = table.PrimaryKey;

    // Get the number of elements in the array.
    Console.WriteLine("Column Count: " + columns.Length);
    for(int i = 0; i < columns.Length; i++)
    {
        Console.WriteLine(columns[i].ColumnName + columns[i].DataType);
    }
}
 
private void SetPrimaryKeys()
{
    // Create a new DataTable and set two DataColumn objects as primary
 keys.
    DataTable table = new DataTable();
    DataColumn[] keys = new DataColumn[2];
    DataColumn column;

    // Create column 1.
    column = new DataColumn();
    column.DataType = System.Type.GetType("System.String");
    column.ColumnName= "FirstName";

    // Add the column to the DataTable.Columns collection.
    table.Columns.Add(column);

    // Add the column to the array.
    keys[0] = column;
 
    // Create column 2 and add it to the array.
    column = new DataColumn();
    column.DataType = System.Type.GetType("System.String");
    column.ColumnName = "LastName";
    table.Columns.Add(column);

    // Add the column to the array.
    keys[1] = column;

    // Set the PrimaryKeys property to the array.
    table.PrimaryKey = keys;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataTable クラス
DataTable メンバ
System.Data 名前空間
DataColumn クラス
DataTable.PrimaryKey プロパティ
DataColumnCollection クラス
その他の技術情報
DataTable の作成使用


このページでは「.NET Framework クラス ライブラリ リファレンス」からDataTable.PrimaryKey プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDataTable.PrimaryKey プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDataTable.PrimaryKey プロパティ を検索

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

辞書ショートカット

すべての辞書の索引

DataTable.PrimaryKey プロパティのお隣キーワード
検索ランキング

   

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



DataTable.PrimaryKey プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS