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

Dim instance As DataTable Dim returnValue As DataRow returnValue = instance.NewRow
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; }

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に収録されているすべての辞書からDataTable.NewRow メソッドを検索する場合は、下記のリンクをクリックしてください。

- DataTable.NewRow メソッドのページへのリンク