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

DataTable.NewRow メソッド

テーブルと同じスキーマ新しい DataRow を作成します

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

Public Function NewRow As
 DataRow
Dim instance As DataTable
Dim returnValue As DataRow

returnValue = instance.NewRow
public DataRow NewRow ()
public:
DataRow^ NewRow ()
public DataRow NewRow ()
public function NewRow () : DataRow

戻り値
DataTable と同じスキーマを持つ DataRow

解説解説

DataTable と同じスキーマを持つ新しDataRow オブジェクト作成するには、NewRow メソッド使用する必要がありますDataRow作成した後で、これを DataTable オブジェクトRows プロパティ使用して、DataRowCollection に追加できます

使用例使用例

DataTable作成しテーブルスキーマ決定する 2 つの DataColumn オブジェクト追加しNewRow メソッド使用して複数新しDataRow オブジェクト作成する例を次に示します次にAdd メソッド使用して、これらの DataRow オブジェクトDataRowCollection追加します

Private Sub MakeDataTableAndDisplay()
    ' Create new DataTable and DataSource objects.
    Dim table As DataTable = New
 DataTable()

    ' Declare DataColumn and DataRow variables.
    Dim column As DataColumn 
    Dim row As DataRow 
    Dim view As DataView 

    ' Create new DataColumn, set DataType, ColumnName and add to DataTable.
    
    column = New DataColumn()
    column.DataType = System.Type.GetType("System.Int32")
    column.ColumnName = "id"
    table.Columns.Add(column)
 
    ' Create second column.
    column = New DataColumn()
    column.DataType = Type.GetType("System.String")
    column.ColumnName = "item"
    table.Columns.Add(column)
 
    ' Create new DataRow objects and add to DataTable.    
    Dim i As Integer
    For i = 0 to 9 
       row = table.NewRow()
       row("id") = i
       row("item") = "item "
 & i
       table.Rows.Add(row)
    Next
    ' Create a DataView using the DataTable.
    view = New DataView(table)

    ' Set a DataGrid control's DataSource to the DataView.
    DataGrid1.DataSource = view
End Sub
private void MakeDataTableAndDisplay()
{
    // Create new DataTable and DataSource objects.
    DataTable table = new DataTable();

    // Declare DataColumn and DataRow variables.
    DataColumn column;
    DataRow row; 
    DataView view;

    // Create new DataColumn, set DataType, ColumnName and add to DataTable.
    
    column = new DataColumn();
    column.DataType = System.Type.GetType("System.Int32");
    column.ColumnName = "id";
    table.Columns.Add(column);
 
    // Create second column.
    column = new DataColumn();
    column.DataType = Type.GetType("System.String");
    column.ColumnName = "item";
    table.Columns.Add(column);
 
    // Create new DataRow objects and add to DataTable.    
    for(int i = 0; i < 10; i++)
    {
        row = table.NewRow();
        row["id"] = i;
        row["item"] = "item " + i.ToString();
        table.Rows.Add(row);
    }
 
    // Create a DataView using the DataTable.
    view = new DataView(table);

    // Set a DataGrid control's DataSource to the DataView.
    dataGrid1.DataSource = view;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataTable クラス
DataTable メンバ
System.Data 名前空間
AcceptChanges
DataColumnCollection クラス
その他の技術情報
DataTable の作成使用


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

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

辞書ショートカット

すべての辞書の索引

「DataTable.NewRow メソッド」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS