DataSet.Loadとは? わかりやすく解説

DataSet.Load メソッド (IDataReader, LoadOption, DataTable[])

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

指定した IDataReader使用するデータ ソースの値を DataSet格納しDataTable インスタンス配列使用してスキーマ情報名前空間情報指定します

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

Public Sub Load ( _
    reader As IDataReader, _
    loadOption As LoadOption, _
    ParamArray tables As DataTable() _
)
Dim instance As DataSet
Dim reader As IDataReader
Dim loadOption As LoadOption
Dim tables As DataTable()

instance.Load(reader, loadOption, tables)
public void Load (
    IDataReader reader,
    LoadOption loadOption,
    params DataTable[] tables
)
public:
void Load (
    IDataReader^ reader, 
    LoadOption loadOption, 
    ... array<DataTable^>^ tables
)
public void Load (
    IDataReader reader, 
    LoadOption loadOption, 
    DataTable[] tables
)
public function Load (
    reader : IDataReader, 
    loadOption : LoadOption, 
    ... tables : DataTable[]
)

パラメータ

reader

1 つ上の結果セットを含む IDataReader。

loadOption

LoadOption 列挙体の値。DataSet 内の DataTable インスタンスに既に含まれている行を同じ主キーを持つ受信した行と結合する方法示します

tables

Load メソッドが名前と名前空間情報取得するDataTable インスタンス配列。これらのテーブルは、この DataSet格納されている DataTableCollection のメンバである必要があります

解説解説
使用例使用例

次に示す例では、新しDataSet作成し2 つDataTable インスタンスDataSet追加した後、Load メソッド使用して DataSet入力し2 つ結果セットを含む DataTableReader からデータ取得します最後にコンソール ウィンドウテーブル内容表示します

Sub Main()
    Dim dataSet As New DataSet

    Dim customerTable As New
 DataTable
    Dim productTable As New
 DataTable

    ' This information is cosmetic, only.
    customerTable.TableName = "Customers"
    productTable.TableName = "Products"

    ' Add the tables to the DataSet:
    dataSet.Tables.Add(customerTable)
    dataSet.Tables.Add(productTable)

    ' Load the data into the existing DataSet. 
    Dim reader As DataTableReader = GetReader()
    dataSet.Load(reader, LoadOption.OverwriteChanges, _
        customerTable, productTable)

    ' Print out the contents of each table:
    For Each table As DataTable
 In dataSet.Tables
        PrintColumns(table)
    Next

    Console.WriteLine("Press any key to continue.")
    Console.ReadKey()
End Sub

Private Function GetCustomers() As
 DataTable
    ' Create sample Customers table.
    Dim table As New DataTable
    table.TableName = "Customers"

    ' Create two columns, ID and Name.
    Dim idColumn As DataColumn = table.Columns.Add("ID",
 _
        GetType(Integer))
    table.Columns.Add("Name", GetType(String))

    ' Set the ID column as the primary key column.
    table.PrimaryKey = New DataColumn() {idColumn}

    table.Rows.Add(New Object() {0, "Mary"})
    table.Rows.Add(New Object() {1, "Andy"})
    table.Rows.Add(New Object() {2, "Peter"})
    table.AcceptChanges()
    Return table
End Function

Private Function GetProducts() As
 DataTable
    ' Create sample Products table, in order
    ' to demonstrate the behavior of the DataTableReader.
    Dim table As New DataTable
    table.TableName = "Products"

    ' Create two columns, ID and Name.
    Dim idColumn As DataColumn = table.Columns.Add("ID",
 _
        GetType(Integer))
    table.Columns.Add("Name", GetType(String))

    ' Set the ID column as the primary key column.
    table.PrimaryKey = New DataColumn() {idColumn}

    table.Rows.Add(New Object() {0, "Wireless
 Network Card"})
    table.Rows.Add(New Object() {1, "Hard
 Drive"})
    table.Rows.Add(New Object() {2, "Monitor"})
    table.Rows.Add(New Object() {3, "CPU"})
    Return table
End Function

Private Function GetReader() As
 DataTableReader
    ' Return a DataTableReader containing multiple
    ' result sets, just for the sake of this demo.
    Dim dataSet As New DataSet
    dataSet.Tables.Add(GetCustomers())
    dataSet.Tables.Add(GetProducts())
    Return dataSet.CreateDataReader()
End Function

Private Sub PrintColumns( _
   ByVal table As DataTable)

    Console.WriteLine()
    Console.WriteLine(table.TableName)
    Console.WriteLine("=========================")
    ' Loop through all the rows in the table.
    For Each row As DataRow
 In table.Rows
        For Each col As
 DataColumn In table.Columns
            Console.Write(row(col).ToString() & " ")
        Next
        Console.WriteLine()
    Next
End Sub
static void Main()
{
    DataSet dataSet = new DataSet();

    DataTable customerTable = new DataTable();
    DataTable productTable = new DataTable();

    // This information is cosmetic, only.
    customerTable.TableName = "Customers";
    productTable.TableName = "Products";

    // Add the tables to the DataSet:
    dataSet.Tables.Add(customerTable);
    dataSet.Tables.Add(productTable);

    // Load the data into the existing DataSet. 
    DataTableReader reader = GetReader();
    dataSet.Load(reader, LoadOption.OverwriteChanges,
        customerTable, productTable);

    // Print out the contents of each table:
    foreach (DataTable table in dataSet.Tables)
    {
        PrintColumns(table);
    }

    Console.WriteLine("Press any key to continue.");
    Console.ReadKey();
}

private static DataTable GetCustomers()
{
    // Create sample Customers table.
    DataTable table = new DataTable();
    table.TableName = "Customers";

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 0, "Mary" });
    table.Rows.Add(new object[] { 1, "Andy" });
    table.Rows.Add(new object[] { 2, "Peter" });
    table.AcceptChanges();
    return table;
}

private static DataTable GetProducts()
{
    // Create sample Products table.
    DataTable table = new DataTable();
    table.TableName = "Products";

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID",
        typeof(int));
    table.Columns.Add("Name", typeof(string));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 0, "Wireless Network Card"
 });
    table.Rows.Add(new object[] { 1, "Hard Drive" });
    table.Rows.Add(new object[] { 2, "Monitor" });
    table.Rows.Add(new object[] { 3, "CPU" });
    table.AcceptChanges();
    return table;
}

private static void PrintColumns(DataTable
 table)
{
    Console.WriteLine();
    Console.WriteLine(table.TableName);
    Console.WriteLine("=========================");
    // Loop through all the rows in the table:
    foreach (DataRow row in table.Rows)
    {
        for (int i = 0; i < table.Columns.Count;
 i++)
        {
            Console.Write(row[i] + " ");
        }
        Console.WriteLine();
    }
}

private static DataTableReader GetReader()
{
    // Return a DataTableReader containing multiple
    // result sets, just for the sake of this demo.
    DataSet dataSet = new DataSet();
    dataSet.Tables.Add(GetCustomers());
    dataSet.Tables.Add(GetProducts());
    return dataSet.CreateDataReader();
}

この例では、コンソール ウィンドウ次の出力表示します

Customers
=========================
0 Mary
1 Andy
2 Peter

Products
=========================
0 Wireless Network Card
1 Hard Drive
2 Monitor
3 CPU
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DataSet.Load メソッド (IDataReader, LoadOption, FillErrorEventHandler, DataTable[])

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

指定した IDataReader使用するデータ ソースの値を DataSet格納しDataTable インスタンス配列使用してスキーマ情報名前空間情報指定します

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

Public Overridable Sub Load
 ( _
    reader As IDataReader, _
    loadOption As LoadOption, _
    errorHandler As FillErrorEventHandler, _
    ParamArray tables As DataTable() _
)
Dim instance As DataSet
Dim reader As IDataReader
Dim loadOption As LoadOption
Dim errorHandler As FillErrorEventHandler
Dim tables As DataTable()

instance.Load(reader, loadOption, errorHandler, tables)
public virtual void Load (
    IDataReader reader,
    LoadOption loadOption,
    FillErrorEventHandler errorHandler,
    params DataTable[] tables
)
public:
virtual void Load (
    IDataReader^ reader, 
    LoadOption loadOption, 
    FillErrorEventHandler^ errorHandler, 
    ... array<DataTable^>^ tables
)
public void Load (
    IDataReader reader, 
    LoadOption loadOption, 
    FillErrorEventHandler errorHandler, 
    DataTable[] tables
)
public function Load (
    reader : IDataReader, 
    loadOption : LoadOption, 
    errorHandler : FillErrorEventHandler, 
    ... tables : DataTable[]
)

パラメータ

reader

1 つ上の結果セットを含む IDataReader。

loadOption

LoadOption 列挙体の値。DataSet 内の DataTable インスタンスに既に含まれている行を同じ主キーを持つ受信した行と結合する方法示します

errorHandler

データ読み込み中にエラーが発生した場合呼び出される FillErrorEventHandler デリゲート

tables

Load メソッドが名前と名前空間情報取得するDataTable インスタンス配列

解説解説

Load メソッドは、単一DataTable に、IDataReaderインスタンスか取得したデータ挿入する手段提供します。このメソッドは同じ機能提供しますが、複数結果セットIDataReader から読み込んでDataSet 内の複数テーブル格納します

loadOption パラメータ使用して既存データに対してデータインポートする方法指定できます。このパラメータには、LoadOption 列挙体の任意の値を設定できます。このパラメータ使用方法詳細については、DataTableLoad メソッドに関するドキュメント参照してください

errorHandler パラメータは、データ読み込み中にエラーが発生した場合呼び出されるプロシージャ参照する FillErrorEventHandler デリゲートです。プロシージャに FillErrorEventArgs パラメータを渡すことで得られるプロパティ使用して発生したエラーデータ現在の行、入力先の DataTable に関する情報取得できます単純な try/catch ブロック使用せず、このデリゲート機構使用することで、エラー特定状況の処理を行い、さらに必要であれば処理を続行できますFillErrorEventArgs パラメータには Continue プロパティありますエラーの処理後に処理を続行することを指定するには、このプロパティtrue設定します。処理を停止するには、このプロパティfalse設定します。このプロパティfalse設定すると、問題の原因となったコードによって例外スローされるので注意してください

tables パラメータ使用して DataTable インスタンス配列指定することで、リーダーによって読み込まれ結果セットそれぞれ対応するテーブル順序指定できますLoad メソッドは、ソース データ リーダーから得た単一結果セットデータ指定したDataTable インスタンス格納します1 つ結果セット操作が終わると、Load メソッドリーダー内の次の結果セット操作します。これをすべての結果セットについて行います

このメソッド名前解決スキームは、DbDataAdapter クラスFill メソッド使用されるスキームと同じです。

使用例使用例

次に示す例では、テーブルDataSet追加した後、Load メソッド使用して互換性のないスキーマを含む DataTableReader からデータ読み込みます。この例ではエラートラップするのではなくFillErrorEventHandler デリゲート使用してエラー調査し処理します

Sub Main()
  Dim dataSet As New DataSet
  Dim table As New DataTable()

  ' Attempt to load data from a data reader in which
  ' the schema is incompatible with the current schema.
  ' If you use exception handling, you won't get the chance
  ' to examine each row, and each individual table,
  ' as the Load method progresses.
  ' By taking advantage of the FillErrorEventHandler delegate,
  ' you can interact with the Load process as an error occurs,
  ' attempting to fix the problem, or simply continuing or quitting
  ' the Load process.:
  dataSet = New DataSet()
  table = GetIntegerTable()
  dataSet.Tables.Add(table)
  Dim reader As New DataTableReader(GetStringTable())
  dataSet.Load(reader, LoadOption.OverwriteChanges, _
      AddressOf FillErrorHandler, table)

  Console.WriteLine("Press any key to continue.")
  Console.ReadKey()
End Sub

Private Sub FillErrorHandler(ByVal
 sender As Object, _
  ByVal e As FillErrorEventArgs)
  ' You can use the e.Errors value to determine exactly what
  ' went wrong.
  If e.Errors.GetType Is GetType(System.FormatException)
 Then
    Console.WriteLine("Error when attempting to update the value:
 {0}", _
      e.Values(0))
  End If

  ' Setting e.Continue to True tells the Load
  ' method to continue trying. Setting it to False
  ' indicates that an error has occurred, and the 
  ' Load method raises the exception that got 
  ' you here.
  e.Continue = True
End Sub

Private Function GetIntegerTable() As
 DataTable
  ' Create sample table with a single Int32 column.
  Dim table As New DataTable

  Dim idColumn As DataColumn = table.Columns.Add("ID",
 _
      GetType(Integer))

  ' Set the ID column as the primary key column.
  table.PrimaryKey = New DataColumn() {idColumn}

  table.Rows.Add(New Object() {4})
  table.Rows.Add(New Object() {5})
  table.TableName = "IntegerTable"
  table.AcceptChanges()
  Return table
End Function

Private Function GetStringTable() As
 DataTable
  ' Create sample table with a single String column.
  Dim table As New DataTable

  Dim idColumn As DataColumn = table.Columns.Add("ID",
 _
      GetType(String))

  ' Set the ID column as the primary key column.
  table.PrimaryKey = New DataColumn() {idColumn}

  table.Rows.Add(New Object() {"Mary"})
  table.Rows.Add(New Object() {"Andy"})
  table.Rows.Add(New Object() {"Peter"})
  table.AcceptChanges()
  Return table
End Function

Private Sub PrintColumns( _
   ByVal table As DataTable)

  ' Loop through all the rows in the DataTableReader.
  For Each row As DataRow
 In table.Rows
    For Each col As DataColumn
 In table.Columns
      Console.Write(row(col).ToString() & " ")
    Next
    Console.WriteLine()
  Next
End Sub
static void Main()
{
    // Attempt to load data from a data reader in which
    // the schema is incompatible with the current schema.
    // If you use exception handling, you won't get the chance
    // to examine each row, and each individual table,
    // as the Load method progresses.
    // By taking advantage of the FillErrorEventHandler delegate,
    // you can interact with the Load process as an error occurs,
    // attempting to fix the problem, or simply continuing or quitting
    // the Load process.:
    DataSet dataSet = new DataSet();
    DataTable table = GetIntegerTable();
    dataSet.Tables.Add(table);
    DataTableReader reader = new DataTableReader(GetStringTable());
    dataSet.Load(reader, LoadOption.OverwriteChanges, 
        FillErrorHandler, table);

    Console.WriteLine("Press any key to continue.");
    Console.ReadKey();
}

private static DataTable GetIntegerTable()
{
    // Create sample Customers table, in order
    // to demonstrate the behavior of the DataTableReader.
    DataTable table = new DataTable();

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(int));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 4 });
    table.Rows.Add(new object[] { 5 });
    table.AcceptChanges();
    return table;
}

private static DataTable GetStringTable()
{
    // Create sample Customers table, in order
    // to demonstrate the behavior of the DataTableReader.
    DataTable table = new DataTable();

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(string));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { "Mary" });
    table.Rows.Add(new object[] { "Andy" });
    table.Rows.Add(new object[] { "Peter" });
    table.AcceptChanges();
    return table;
}

static void FillErrorHandler(object sender,
 FillErrorEventArgs e)
{
    // You can use the e.Errors value to determine exactly what
    // went wrong.
    if (e.Errors.GetType() == typeof(System.FormatException))
    {
        Console.WriteLine("Error when attempting to update the value: {0}",
 
            e.Values[0]);
    }

    // Setting e.Continue to True tells the Load
    // method to continue trying. Setting it to False
    // indicates that an error has occurred, and the 
    // Load method raises the exception that got 
    // you here.
    e.Continue = true;
}

この例では、コンソール ウィンドウ次の出力表示します

Error when attempting to update the value: Mary
Error when attempting to update the value: Andy
Error when attempting to update the value: Peter
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DataSet.Load メソッド (IDataReader, LoadOption, String[])

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

指定した IDataReader使用するデータ ソースの値を DataSet格納し文字列配列使用して DataSet 内のテーブルの名前を指定します

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

Public Sub Load ( _
    reader As IDataReader, _
    loadOption As LoadOption, _
    ParamArray tables As String()
 _
)
Dim instance As DataSet
Dim reader As IDataReader
Dim loadOption As LoadOption
Dim tables As String()

instance.Load(reader, loadOption, tables)
public void Load (
    IDataReader reader,
    LoadOption loadOption,
    params string[] tables
)
public:
void Load (
    IDataReader^ reader, 
    LoadOption loadOption, 
    ... array<String^>^ tables
)
public void Load (
    IDataReader reader, 
    LoadOption loadOption, 
    String[] tables
)
public function Load (
    reader : IDataReader, 
    loadOption : LoadOption, 
    ... tables : String[]
)

パラメータ

reader

1 つ上の結果セットを含む IDataReader。

loadOption

LoadOption 列挙体の値。DataSet 内の DataTable インスタンスに既に含まれている行を同じ主キーを持つ受信した行と結合する方法示します

tables

Load メソッドテーブル名の情報取得する文字列配列

解説解説

Load メソッドは、単一DataTable に、IDataReaderインスタンスか取得したデータ挿入する手段提供します。このメソッドは同じ機能提供しますが、複数結果セットIDataReader から読み込んでDataSet 内の複数テーブル格納します

loadOption パラメータ使用して既存データに対してデータインポートする方法指定できます。このパラメータには、LoadOption 列挙体の任意の値を設定できます。このパラメータ使用方法詳細については、Load メソッドに関するドキュメント参照してください

tables パラメータ使用してテーブル名の配列指定することで、リーダーによって読み込まれ結果セットそれぞれ対応するテーブル順序指定できますLoad メソッドは、テーブル名の配列含まれている名前を順番DataSetで検索し、一致するテーブル探します一致するテーブルが見つかると、そのテーブル現在の結果セットの内容読み込まれます。一致するテーブルが見つからない場合テーブル名の配列指定されている名前を使用してテーブル作成されます。新しテーブルスキーマは、結果セットか推測されます。1 つ結果セット操作が終わると、Load メソッドリーダー内の次の結果セット操作します。これをすべての結果セットについて行います

DataSet既定名前空間関連付けられている場合新しく作成されDataTable にはその名前空間関連付けられます。このメソッド名前解決スキームは、DbDataAdapter クラスFill メソッド使用されるスキームと同じです。

使用例使用例

次に示すコンソール アプリケーションの例では、最初にテーブル作成しLoad メソッド使用してリーダーデータDataSet読み込みます。次にDataSetテーブル追加し、そのテーブルに DataTableReader のデータ格納します。この例では、存在しないテーブルの名前を示すパラメータLoad メソッドに渡すため、パラメータとして渡された名前に一致する新しテーブルLoad メソッドによって作成されます。データ読み込まれた後、すべてのテーブル内容コンソール ウィンドウ表示されます。

Sub Main()
  Dim dataSet As New DataSet
  Dim table As DataTable

  Dim reader As DataTableReader = GetReader()

  ' The tables listed as parameters for the Load method 
  ' should be in the same order as the tables within the IDataReader.
  dataSet.Load(reader, LoadOption.Upsert, "Customers",
 "Products")
  For Each table In dataSet.Tables
    PrintColumns(table)
  Next

  ' Now try the example with the DataSet
  ' already filled with data:
  dataSet = New DataSet
  dataSet.Tables.Add(GetCustomers())
  dataSet.Tables.Add(GetProducts())

  ' Retrieve a data reader containing changed data:
  reader = GetReader()

  ' Load the data into the existing DataSet. Retrieve the order of the
  ' the data in the reader from the
  ' list of table names in the parameters. If you specify
  ' a new table name here, the Load method will create
  ' a corresponding new table.
  dataSet.Load(reader, LoadOption.Upsert, "NewCustomers",
 "Products")
  For Each table In dataSet.Tables
    PrintColumns(table)
  Next

  Console.WriteLine("Press any key to continue.")
  Console.ReadKey()
End Sub

Private Function GetCustomers() As
 DataTable
  ' Create sample Customers table.
  Dim table As New DataTable
  table.TableName = "Customers"

  ' Create two columns, ID and Name.
  Dim idColumn As DataColumn = table.Columns.Add("ID",
 GetType(Integer))
  table.Columns.Add("Name", GetType(String))

  ' Set the ID column as the primary key column.
  table.PrimaryKey = New DataColumn() {idColumn}

  table.Rows.Add(New Object() {0, "Mary"})
  table.Rows.Add(New Object() {1, "Andy"})
  table.Rows.Add(New Object() {2, "Peter"})
  table.AcceptChanges()
  Return table
End Function

Private Function GetProducts() As
 DataTable
  ' Create sample Products table, in order
  ' to demonstrate the behavior of the DataTableReader.
  Dim table As New DataTable
  table.TableName = "Products"

  ' Create two columns, ID and Name.
  Dim idColumn As DataColumn = table.Columns.Add("ID",
 GetType(Integer))
  table.Columns.Add("Name", GetType(String))

  ' Set the ID column as the primary key column.
  table.PrimaryKey = New DataColumn() {idColumn}

  table.Rows.Add(New Object() {0, "Wireless
 Network Card"})
  table.Rows.Add(New Object() {1, "Hard
 Drive"})
  table.Rows.Add(New Object() {2, "Monitor"})
  table.Rows.Add(New Object() {3, "CPU"})
  Return table
End Function

Private Function GetReader() As
 DataTableReader
  ' Return a DataTableReader containing multiple
  ' result sets, just for the sake of this demo.
  Dim dataSet As New DataSet
  dataSet.Tables.Add(GetCustomers())
  dataSet.Tables.Add(GetProducts())
  Return dataSet.CreateDataReader()
End Function

Private Sub PrintColumns( _
   ByVal table As DataTable)

  Console.WriteLine()
  Console.WriteLine(table.TableName)
  Console.WriteLine("=========================")
  ' Loop through all the rows in the table.
  For Each row As DataRow
 In table.Rows
    For Each col As DataColumn
 In table.Columns
      Console.Write(row(col).ToString() & " ")
    Next
    Console.WriteLine()
  Next
End Sub
static void Main()
{
    DataSet dataSet = new DataSet();

    DataTableReader reader = GetReader();

    // The tables listed as parameters for the Load method 
    // should be in the same order as the tables within the IDataReader.
    dataSet.Load(reader, LoadOption.Upsert, "Customers", "Products");
    foreach (DataTable table in dataSet.Tables)
    {
        PrintColumns(table);
    }

    // Now try the example with the DataSet
    // already filled with data:
    dataSet = new DataSet();
    dataSet.Tables.Add(GetCustomers());
    dataSet.Tables.Add(GetProducts());

    // Retrieve a data reader containing changed data:
    reader = GetReader();

    // Load the data into the existing DataSet. Retrieve the order of
 the
    // the data in the reader from the
    // list of table names in the parameters. If you specify
    // a new table name here, the Load method will create
    // a corresponding new table.
    dataSet.Load(reader, LoadOption.Upsert, 
        "NewCustomers", "Products");
    foreach (DataTable table in dataSet.Tables)
    {
        PrintColumns(table);
    }

    Console.WriteLine("Press any key to continue.");
    Console.ReadKey();
}

private static DataTable GetCustomers()
{
    // Create sample Customers table.
    DataTable table = new DataTable();
    table.TableName = "Customers";

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 0, "Mary" });
    table.Rows.Add(new object[] { 1, "Andy" });
    table.Rows.Add(new object[] { 2, "Peter" });
    table.AcceptChanges();
    return table;
}

private static DataTable GetProducts()
{
    // Create sample Products table.
    DataTable table = new DataTable();
    table.TableName = "Products";

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string));

    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 0, "Wireless Network Card"
 });
    table.Rows.Add(new object[] { 1, "Hard Drive" });
    table.Rows.Add(new object[] { 2, "Monitor" });
    table.Rows.Add(new object[] { 3, "CPU" });
    table.AcceptChanges();
    return table;
}

private static void PrintColumns(DataTable
 table)
{
    Console.WriteLine();
    Console.WriteLine(table.TableName);
    Console.WriteLine("=========================");
    // Loop through all the rows in the table:
    foreach (DataRow row in table.Rows)
    {
        for (int i = 0; i < table.Columns.Count;
 i++)
        {
            Console.Write(row[i] + " ");
        }
        Console.WriteLine();
    }
}

private static DataTableReader GetReader()
{
    // Return a DataTableReader containing multiple
    // result sets, just for the sake of this demo.
    DataSet dataSet = new DataSet();
    dataSet.Tables.Add(GetCustomers());
    dataSet.Tables.Add(GetProducts());
    return dataSet.CreateDataReader();
}

この例では、コンソール ウィンドウ次のテキスト表示されます。

Customers
=========================
0 Mary
1 Andy
2 Peter

Products
=========================
0 Wireless Network Card
1 Hard Drive
2 Monitor
3 CPU

Customers
=========================
0 Mary
1 Andy
2 Peter

Products
=========================
0 Wireless Network Card
1 Hard Drive
2 Monitor
3 CPU

NewCustomers
=========================
0 Mary
1 Andy
2 Peter
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DataSet.Load メソッド

指定された IDataReader を使用しDataSetデータ ソースからの値を設定します
オーバーロードの一覧オーバーロードの一覧

名前 説明
DataSet.Load (IDataReader, LoadOption, DataTable[]) 指定した IDataReader使用するデータ ソースの値を DataSet格納しDataTable インスタンス配列使用してスキーマ情報名前空間情報指定します

.NET Compact Framework によってサポートされています。

DataSet.Load (IDataReader, LoadOption, String[]) 指定した IDataReader使用するデータ ソースの値を DataSet格納し文字列配列使用して DataSet 内のテーブルの名前を指定します

.NET Compact Framework によってサポートされています。

DataSet.Load (IDataReader, LoadOption, FillErrorEventHandler, DataTable[]) 指定した IDataReader使用するデータ ソースの値を DataSet格納しDataTable インスタンス配列使用してスキーマ情報名前空間情報指定します

.NET Compact Framework によってサポートされています。

参照参照

関連項目

DataSet クラス
DataSet メンバ
System.Data 名前空間

その他の技術情報

ADO.NET での DataSet使用
ADO.NET での DataSet使用


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

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

辞書ショートカット

カテゴリ一覧

すべての辞書の索引



Weblioのサービス

「DataSet.Load」の関連用語



DataSet.Loadのお隣キーワード
検索ランキング

   

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



DataSet.Loadのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS