DataTableCollection.AddRange(DataTable[]) メソッド
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した DataTable 配列の要素をコレクションの末尾にコピーします。
public:
void AddRange(cli::array <System::Data::DataTable ^> ^ tables);
C#
public void AddRange (System.Data.DataTable?[]? tables);
C#
public void AddRange (System.Data.DataTable[] tables);
member this.AddRange : System.Data.DataTable[] -> unit
Public Sub AddRange (tables As DataTable())
次の例では、2 つのDataTableオブジェクトを作成し、 の DataSetにDataTableCollection追加します。
C#
public static void DataTableCollectionAddRange()
{
// create a DataSet with two tables
DataSet dataSet = new DataSet();
// create Customer table
DataTable customersTable = new DataTable("Customers");
customersTable.Columns.Add("customerId",
typeof(int)).AutoIncrement = true;
customersTable.Columns.Add("name",
typeof(string));
customersTable.PrimaryKey = new DataColumn[] { customersTable.Columns["customerId"] };
// create Orders table
DataTable ordersTable = new DataTable("Orders");
ordersTable.Columns.Add("orderId",
typeof(int)).AutoIncrement = true;
ordersTable.Columns.Add("customerId",
typeof(int));
ordersTable.Columns.Add("amount",
typeof(double));
ordersTable.PrimaryKey = new DataColumn[] { ordersTable.Columns["orderId"] };
dataSet.Tables.AddRange(new DataTable[] { customersTable, ordersTable });
// print the tables and their columns
foreach (DataTable table in dataSet.Tables)
{
Console.WriteLine(table.TableName);
foreach (DataColumn column in table.Columns)
{
Console.Write("{0}\table", column.ColumnName);
}
Console.WriteLine();
}
}
Public Sub DataTableCollectionAddRange()
' create a DataSet with two tables
Dim dataSet As New DataSet()
' create Customer table
Dim customersTable As New DataTable("Customers")
customersTable.Columns.Add("customerId", _
Type.GetType("System.Int32")).AutoIncrement = True
customersTable.Columns.Add("name", Type.GetType("System.String"))
customersTable.PrimaryKey = New DataColumn() _
{customersTable.Columns("customerId")}
' create Orders table
Dim ordersTable As New DataTable("Orders")
ordersTable.Columns.Add("orderId", _
Type.GetType("System.Int32")).AutoIncrement = True
ordersTable.Columns.Add("customerId", _
Type.GetType("System.Int32"))
ordersTable.Columns.Add("amount", _
Type.GetType("System.Double"))
ordersTable.PrimaryKey = New DataColumn() _
{ordersTable.Columns("orderId")}
dataSet.Tables.AddRange(New DataTable() {customersTable, ordersTable})
' print the tables and their columns
Dim table As DataTable
Dim column As DataColumn
For Each table In dataSet.Tables
Console.WriteLine(table.TableName)
For Each column In table.Columns
Console.Write("{0}" & vbTab, column.ColumnName)
Next
Console.WriteLine()
Next
End Sub
製品 | バージョン |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。