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

Dim instance As DataTable Dim reader As IDataReader Dim loadOption As LoadOption instance.Load(reader, loadOption)

Load メソッドでは、読み込まれた IDataReader の最初の結果セットが処理されます。処理が正常に完了したら、リーダーの位置が次の結果セット (存在する場合) に設定されます。データを変換する場合、Load メソッドでは Fill メソッドと同じ変換規則が使用されます。
Load メソッドでは、IDataReader インスタンスからデータを読み込む際に、スキーマ、データ、イベント処理の 3 つの問題を考慮する必要があります。スキーマを使用するときに、Load メソッドで発生する可能性がある条件を次の表に示します。このスキーマの動作は、データを含まない結果セットを含め、インポートされるすべての結果セットで発生します。
DataTable にスキーマがない。 | |
Load メソッドにより、DataTable のスキーマに列が追加されます。DataTable 内にある対応する列と読み込まれた結果セットの値に互換性がなければ、このメソッドは例外をスローします。さらにこのメソッドは、追加されているすべての列の結果セットから、制約の情報を取得します。主キー制約の場合を除き、現在の DataTable で読み込み処理の開始位置に列が格納されていない場合にのみ、この制約の情報が使用されます。 | |
欠けている列に既定値が定義されているか、その列のデータ型が null 許容の場合、Load メソッドでは欠けている列を既定値または null 値に置き換えて行を追加できます。既定値がない場合や null を使用できない場合は、Load メソッドは例外をスローします。特に既定値が指定されていない場合、Load メソッドでは暗黙的な既定値として null 値が使用されます。 |
データ操作の観点から Load メソッドの動作を考える前に、各列の現在の値と元の値の両方が DataTable 内の各行で維持されることについて考えてみましょう。値は等しいこともありますが、DataTable への入力後に行内のデータが変更された場合は異なることもあります。詳細については、「行の状態とバージョン」を参照してください。
このメソッド呼び出しでは、指定された LoadOption パラメータによって受信データの処理が変化します。読み込む行に既存の行と同じ主キーが含まれている場合、Load メソッドではどのように処理するのでしょうか。現在の値を変更するのか、元の値を変更するのか、またはその両方なのでしょうか。このような問題は、loadOption パラメータを使用して解決します。
既存の行と受信した行の主キー値が対応している場合、行は現在の行の状態値を使用して処理されるか、新しい行として処理されます。
イベント処理の観点から見ると、RowChanging イベントは各行が変更される前に発生し、RowChanged イベントは各行が変更された後に発生します。どちらの場合でも、イベント ハンドラに渡される DataRowChangeEventArgs インスタンスの Action プロパティに、イベントに関連付けられている特定のアクションに関する情報が格納されます。このアクション値は、読み込み操作の前の行の状態に応じて変わります。どちらの場合でも、両方のイベントが発生し、アクションは同じになります。現在の行の状態に応じて、アクションは各行の現在のバージョンまたは元のバージョン、あるいは両方のバージョンに適用されます。
Load メソッドを LoadOption の各値を使って呼び出したときの動作を次の表に示します。また、それらの値と読み込む行の行状態との関係も示します。"(存在せず)" と表記された最後の行は、受信した行が既存の行と一致しなかった場合の動作を表します。この表の各マスに、行内のフィールドの現在の値と元の値、および Load メソッドが完了した後の値の DataRowState を示します。
既存の DataRowState | OverwriteChanges | ||
---|---|---|---|
元の値 = -<Not available> 状態 = <Added> RowAction = Change | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal | 元の値 = <Incoming> 状態 = <Modified> RowAction = ChangeOriginal | |
元の値 = <Existing> 状態 = <Modified> RowAction = Change | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal | 元の値 = <Incoming> 状態 = <Modified> RowAction =ChangeOriginal | |
現在の値 = --- 元の値 = <Existing> 状態 = <Deleted> 元の値 = <Not available> 状態 = <Added> RowAction = Add | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal | 現在の値 = <Not available> 元の値 = <Incoming> 状態 = <Deleted> RowAction = ChangeOriginal | |
元の値 = <Existing> 状態 = <Unchanged> RowAction = Nothing 状態 = <Modified> RowAction = Change | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal | |
(存在せず) | 元の値 = <Not available> 状態 = <Added> RowAction = Add | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal |
DataColumn の値は、ReadOnly や AutoIncrement などのプロパティを使用することで制約できます。Load メソッドでは、このような列を、列のプロパティで定義された動作に応じた方法で処理します。DataColumn に対する読み取り専用制約は、メモリ内で発生する変更にのみ適用されます。Load メソッドでは、必要に応じて読み取り専用列の値も上書きされます。
Load メソッドを呼び出すときに OverwriteChanges オプションまたは PreserveChanges オプションを指定した場合、受信データは DataTable の主データ ソースから受信されており、DataTable によって変更が追跡され、変更をデータ ソースに反映できることが想定されます。Upsert オプションを選択した場合、データは中間層コンポーネントから得られるデータなどの 2 次データ ソースの 1 つから受信されていることが想定されます。これはユーザーにより変更されている可能性があります。その場合、DataTable 内の 1 つ以上のデータ ソースのデータを集約した後、そのデータを主データ ソースに反映する意図があることが想定されます。主キーの比較に使用する行のバージョンを特定するために、LoadOption パラメータが使用されます。その詳細を次の表で説明します。

Load メソッドの呼び出しに関する問題を次の例にいくつか示します。この例ではまず、読み込まれた IDataReader からのスキーマの推論、互換性のないスキーマの処理、行が欠けていたり多すぎたりするスキーマなど、スキーマの問題を示します。次に、さまざまな読み込みオプションの処理など、データの問題を示します。
Sub Main() Dim table As New DataTable() ' This example examines a number of scenarios involving the ' DataTable.Load method. Console.WriteLine("Load a DataTable and infer its schema:") ' Retrieve a data reader, based on the Customers data. In ' an application, this data might be coming from a middle-tier ' business object: Dim reader As New DataTableReader(GetCustomers()) ' The table has no schema. The Load method will infer the ' schema from the IDataReader: table.Load(reader) PrintColumns(table) Console.WriteLine(" ============================= ") Console.WriteLine( _ "Load a DataTable from an incompatible IDataReader:") ' Create a table with a single integer column. Attempt ' to load data from a reader with a schema that is ' incompatible. Note the exception, determined ' by the particular incompatibility: table = GetIntegerTable() reader = New DataTableReader(GetStringTable()) Try table.Load(reader) Catch ex As Exception Console.WriteLine(ex.GetType.Name & ":" & ex.Message()) End Try Console.WriteLine(" ============================= ") Console.WriteLine( _ "Load a DataTable with an IDataReader that has extra columns:") ' Note that loading a reader with extra columns adds ' the columns to the existing table, if possible: table = GetIntegerTable() reader = New DataTableReader(GetCustomers()) table.Load(reader) PrintColumns(table) Console.WriteLine(" ============================= ") Console.WriteLine( _ "Load a DataTable with an IDataReader that has missing columns:") ' Note that loading a reader with missing columns causes ' the columns to be filled with null data, if possible: table = GetCustomers() reader = New DataTableReader(GetIntegerTable()) table.Load(reader) PrintColumns(table) ' Demonstrate the various possibilites when loading data into ' a DataTable that already contains data. Console.WriteLine(" ============================= ") Console.WriteLine("Demonstrate data considerations:") Console.WriteLine("Current value, Original value, (RowState)") Console.WriteLine(" ============================= ") Console.WriteLine("Original table:") table = SetupModifiedRows() DisplayRowState(table) Console.WriteLine(" ============================= ") Console.WriteLine("Data in IDataReader to be loaded:") DisplayRowState(GetChangedCustomers()) PerformDemo(LoadOption.OverwriteChanges) PerformDemo(LoadOption.PreserveChanges) PerformDemo(LoadOption.Upsert) Console.WriteLine("Press any key to continue.") Console.ReadKey() End Sub Private Sub DisplayRowState(ByVal table As DataTable) For i As Integer = 0 To table.Rows.Count - 1 Dim current As Object = "--" Dim original As Object = "--" Dim rowState As DataRowState = table.Rows(i).RowState ' Attempt to retrieve the current value, which doesn't exist ' for deleted rows: If rowState <> DataRowState.Deleted Then current = table.Rows(i)("Name", DataRowVersion.Current) End If ' Attempt to retrieve the original value, which doesn't exist ' for added rows: If rowState <> DataRowState.Added Then original = table.Rows(i)("Name", DataRowVersion.Original) End If Console.WriteLine("{0}: {1}, {2} ({3})", i, _ current, original, rowState) Next End Sub Private Function GetChangedCustomers() As DataTable ' Create sample Customers table. Dim table As New DataTable ' 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, "XXX"}) table.Rows.Add(New Object() {1, "XXX"}) table.Rows.Add(New Object() {2, "XXX"}) table.Rows.Add(New Object() {3, "XXX"}) table.Rows.Add(New Object() {4, "XXX"}) table.AcceptChanges() Return table End Function Private Function GetCustomers() As DataTable ' Create sample Customers table. Dim table As New DataTable ' 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 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.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 PerformDemo(ByVal optionForLoad As LoadOption) ' Load data into a DataTable, retrieve a DataTableReader containing ' different data, and call the Load method. Depending on the ' LoadOption value passed as a parameter, this procedure displays ' different results in the DataTable. Console.WriteLine(" ============================= ") Console.WriteLine("table.Load(reader, {0})", optionForLoad) Console.WriteLine(" ============================= ") Dim table As DataTable = SetupModifiedRows() Dim reader As New DataTableReader(GetChangedCustomers()) AddHandler table.RowChanging, New _ DataRowChangeEventHandler(AddressOf HandleRowChanging) table.Load(reader, optionForLoad) Console.WriteLine() DisplayRowState(table) End Sub 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 Private Function SetupModifiedRows() As DataTable ' Fill a DataTable with customer info, and ' then modify, delete, and add rows. Dim table As DataTable = GetCustomers() ' Row 0 is unmodified. ' Row 1 is modified. ' Row 2 is deleted. ' Row 3 is added. table.Rows(1)("Name") = "Sydney" table.Rows(2).Delete() Dim row As DataRow = table.NewRow row("ID") = 3 row("Name") = "Melony" table.Rows.Add(row) ' Note that the code doesn't call ' table.AcceptChanges() Return table End Function Private Sub HandleRowChanging(ByVal sender As Object, _ ByVal e As System.Data.DataRowChangeEventArgs) Console.WriteLine( _ "RowChanging event: ID = {0}, action = {1}", e.Row("ID"), e.Action) End Sub
static void Main() { // This example examines a number of scenarios involving the // DataTable.Load method. Console.WriteLine("Load a DataTable and infer its schema:"); // The table has no schema. The Load method will infer the // schema from the IDataReader: DataTable table = new DataTable(); // Retrieve a data reader, based on the Customers data. In // an application, this data might be coming from a middle-tier // business object: DataTableReader reader = new DataTableReader(GetCustomers()); table.Load(reader); PrintColumns(table); Console.WriteLine(" ============================= "); Console.WriteLine( "Load a DataTable from an incompatible IDataReader:"); // Create a table with a single integer column. Attempt // to load data from a reader with a schema that is // incompatible. Note the exception, determined // by the particular incompatibility: table = GetIntegerTable(); reader = new DataTableReader(GetStringTable()); try { table.Load(reader); } catch (Exception ex) { Console.WriteLine(ex.GetType().Name + ":" + ex.Message); } Console.WriteLine(" ============================= "); Console.WriteLine( "Load a DataTable with an IDataReader that has extra columns:"); // Note that loading a reader with extra columns adds // the columns to the existing table, if possible: table = GetIntegerTable(); reader = new DataTableReader(GetCustomers()); table.Load(reader); PrintColumns(table); Console.WriteLine(" ============================= "); Console.WriteLine( "Load a DataTable with an IDataReader that has missing columns:"); // Note that loading a reader with missing columns causes // the columns to be filled with null data, if possible: table = GetCustomers(); reader = new DataTableReader(GetIntegerTable()); table.Load(reader); PrintColumns(table); // Demonstrate the various possibilites when loading data into // a DataTable that already contains data. Console.WriteLine(" ============================= "); Console.WriteLine("Demonstrate data considerations:"); Console.WriteLine("Current value, Original value, (RowState)"); Console.WriteLine(" ============================= "); Console.WriteLine("Original table:"); table = SetupModifiedRows(); DisplayRowState(table); Console.WriteLine(" ============================= "); Console.WriteLine("Data in IDataReader to be loaded:"); DisplayRowState(GetChangedCustomers()); PerformDemo(LoadOption.OverwriteChanges); PerformDemo(LoadOption.PreserveChanges); PerformDemo(LoadOption.Upsert); Console.WriteLine("Press any key to continue."); Console.ReadKey(); } private static void DisplayRowState(DataTable table) { for (int i = 0; i <= table.Rows.Count - 1; i++) { object current = "--"; object original = "--"; DataRowState rowState = table.Rows[i].RowState; // Attempt to retrieve the current value, which doesn't exist // for deleted rows: if (rowState != DataRowState.Deleted) { current = table.Rows[i]["Name", DataRowVersion.Current]; } // Attempt to retrieve the original value, which doesn't exist // for added rows: if (rowState != DataRowState.Added) { original = table.Rows[i]["Name", DataRowVersion.Original]; } Console.WriteLine("{0}: {1}, {2} ({3})", i, current, original, rowState); } } private static DataTable GetChangedCustomers() { // Create sample Customers table. DataTable table = new DataTable(); // 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, "XXX" }); table.Rows.Add(new object[] { 1, "XXX" }); table.Rows.Add(new object[] { 2, "XXX" }); table.Rows.Add(new object[] { 3, "XXX" }); table.Rows.Add(new object[] { 4, "XXX" }); table.AcceptChanges(); return table; } private static DataTable GetCustomers() { // 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)); 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 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; } private static void PerformDemo(LoadOption optionForLoad) { // Load data into a DataTable, retrieve a DataTableReader containing // different data, and call the Load method. Depending on the // LoadOption value passed as a parameter, this procedure displays // different results in the DataTable. Console.WriteLine(" ============================= "); Console.WriteLine("table.Load(reader, {0})", optionForLoad); Console.WriteLine(" ============================= "); DataTable table = SetupModifiedRows(); DataTableReader reader = new DataTableReader(GetChangedCustomers()); table.RowChanging +=new DataRowChangeEventHandler(HandleRowChanging); table.Load(reader, optionForLoad); Console.WriteLine(); DisplayRowState(table); } private static void PrintColumns(DataTable table) { // Loop through all the rows in the DataTableReader foreach (DataRow row in table.Rows) { for (int i = 0; i < table.Columns.Count; i++) { Console.Write(row[i] + " "); } Console.WriteLine(); } } private static DataTable SetupModifiedRows() { // Fill a DataTable with customer info, and // then modify, delete, and add rows. DataTable table = GetCustomers(); // Row 0 is unmodified. // Row 1 is modified. // Row 2 is deleted. // Row 3 is added. table.Rows[1]["Name"] = "Sydney"; table.Rows[2].Delete(); DataRow row = table.NewRow(); row["ID"] = 3; row["Name"] = "Melony"; table.Rows.Add(row); // Note that the code doesn't call // table.AcceptChanges() return table; } static void HandleRowChanging(object sender, DataRowChangeEventArgs e) { Console.WriteLine( "RowChanging event: ID = {0}, action = {1}", e.Row["ID"], e.Action); }

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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


Load メソッドでは、読み込まれた IDataReader の最初の結果セットが処理されます。処理が正常に完了したら、リーダーの位置が次の結果セット (存在する場合) に設定されます。データを変換する場合、Load メソッドでは DbDataAdapter.Fill メソッドと同じ変換規則が使用されます。
Load メソッドでは、IDataReader インスタンスからデータを読み込む際に、スキーマ、データ、イベント処理の 3 つの問題を考慮する必要があります。スキーマを使用するときに、Load メソッドで発生する可能性がある条件を次の表に示します。このスキーマの動作は、データを含まない結果セットを含め、インポートされるすべての結果セットで発生します。
DataTable にスキーマがない。 | |
Load メソッドにより、DataTable のスキーマに列が追加されます。DataTable 内にある対応する列と読み込まれた結果セットの値に互換性がなければ、このメソッドは例外をスローします。さらにこのメソッドは、追加されているすべての列の結果セットから、制約の情報を取得します。主キー制約の場合を除き、現在の DataTable で読み込み処理の開始位置に列が格納されていない場合にのみ、この制約の情報が使用されます。 | |
欠けている列に既定値が定義されているか、その列のデータ型が null 許容の場合、Loadメソッドでは欠けている列を既定値または null 値に置き換えて行を追加できます。既定値がない場合や null を使用できない場合は、Load メソッドは例外をスローします。特に既定値が指定されていない場合、Load メソッドでは暗黙的な既定値として null 値が使用されます。 |
データ操作の観点から Load メソッドの動作を考える前に、各列の現在の値と元の値の両方が DataTable 内の各行で維持されることについて考えてみましょう。値は等しいこともありますが、DataTable への入力後に行内のデータが変更された場合は異なることもあります。詳細については、「行の状態とバージョン」を参照してください。
このバージョンの Load メソッドでは、各行の現在の値を保持し、元の値をそのまま残そうとします(入力データの動作をより詳細に制御するには、DataTable.Load メソッドのトピックを参照してください)。既存の行と受信した行の主キー値が対応している場合、行は現在の行の状態値を使用して処理されるか、新しい行として処理されます。
イベント処理の観点から見ると、RowChanging イベントは各行が変更される前に発生し、RowChanged イベントは各行が変更された後に発生します。どちらの場合でも、イベント ハンドラに渡される DataRowChangeEventArgs インスタンスの Action プロパティに、イベントに関連付けられている特定のアクションに関する情報が格納されます。このアクション値は、読み込み操作の前の行の状態に応じて変わります。どちらの場合でも、両方のイベントが発生し、アクションは同じになります。現在の行の状態に応じて、アクションは各行の現在のバージョンまたは元のバージョン、あるいは両方のバージョンに適用されます。
Load メソッドの動作について、次の表に示します。"(存在せず)" と表記された最後の行は、受信した行が既存の行と一致しなかった場合の動作を表します。この表の各マスに、行内のフィールドの現在の値と元の値、および Load メソッドが完了した後の値の DataRowState を示します。この例では、メソッドで読み込みオプションは指定できず、既定の PreserveChanges が使用されます。
既存の DataRowState | |
---|---|
元の値 = <Incoming> 状態 = <Modified> RowAction = ChangeOriginal | |
元の値 = <Incoming> 状態 = <Modified> RowAction = ChangeOriginal | |
現在の値 = <Not available> 元の値 = <Incoming> 状態 = <Deleted> RowAction = ChangeOriginal | |
元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal | |
(存在せず) | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal |
DataColumn の値は、ReadOnly や AutoIncrement などのプロパティを使用することで制約できます。Load メソッドでは、このような列を、列のプロパティで定義された動作に応じた方法で処理します。DataColumn に対する読み取り専用制約は、メモリ内で発生する変更にのみ適用されます。Load メソッドでは、必要に応じて読み取り専用列の値も上書きされます。
行内の主キー値の元のバージョンが存在する場合、Load メソッドではそれを使用して、現在の行と受信した行の比較に使用される主キー フィールドのバージョンを判断します。それ以外の場合、Load メソッドでは主キー フィールドの現在のバージョンが使用されます。

Load メソッドの呼び出しに関する問題を次の例にいくつか示します。この例ではまず、読み込まれた IDataReader からのスキーマの推論、互換性のないスキーマの処理、行が欠けていたり多すぎたりするスキーマなど、スキーマの問題を示します。次に、Load メソッドを呼び出し、読み込み操作の前と後のデータを表示します。
Sub Main() ' This example examines a number of scenarios involving the ' DataTable.Load method. Console.WriteLine("Load a DataTable and infer its schema:") ' The table has no schema. The Load method will infer the ' schema from the IDataReader: Dim table As New DataTable() ' Retrieve a data reader, based on the Customers data. In ' an application, this data might be coming from a middle-tier ' business object: Dim reader As New DataTableReader(GetCustomers()) table.Load(reader) PrintColumns(table) Console.WriteLine(" ============================= ") Console.WriteLine( _ "Load a DataTable from an incompatible IDataReader:") ' Create a table with a single integer column. Attempt ' to load data from a reader with a schema that is ' incompatible. Note the exception, determined ' by the particular incompatibility: table = GetIntegerTable() reader = New DataTableReader(GetStringTable()) Try table.Load(reader) Catch ex As Exception Console.WriteLine(ex.GetType.Name & ":" & ex.Message()) End Try Console.WriteLine(" ============================= ") Console.WriteLine( _ "Load a DataTable with an IDataReader that has extra columns:") ' Note that loading a reader with extra columns adds ' the columns to the existing table, if possible: table = GetIntegerTable() reader = New DataTableReader(GetCustomers()) table.Load(reader) PrintColumns(table) Console.WriteLine(" ============================= ") Console.WriteLine( _ "Load a DataTable with an IDataReader that has missing columns:") ' Note that loading a reader with missing columns causes ' the columns to be filled with null data, if possible: table = GetCustomers() reader = New DataTableReader(GetIntegerTable()) table.Load(reader) PrintColumns(table) ' Demonstrate the various possibilites when loading data into ' a DataTable that already contains data. Console.WriteLine(" ============================= ") Console.WriteLine("Demonstrate data considerations:") Console.WriteLine("Current value, Original value, (RowState)") Console.WriteLine(" ============================= ") Console.WriteLine("Original table:") table = SetupModifiedRows() DisplayRowState(table) Console.WriteLine(" ============================= ") Console.WriteLine("Data in IDataReader to be loaded:") DisplayRowState(GetChangedCustomers()) ' Load data into a DataTable, retrieve a DataTableReader ' containing different data, and call the Load method. Console.WriteLine(" ============================= ") Console.WriteLine("table.Load(reader)") Console.WriteLine(" ============================= ") table = SetupModifiedRows() reader = New DataTableReader(GetChangedCustomers()) table.Load(reader) DisplayRowState(table) Console.WriteLine("Press any key to continue.") Console.ReadKey() End Sub Private Sub DisplayRowState(ByVal table As DataTable) For i As Integer = 0 To table.Rows.Count - 1 Dim current As Object = "--" Dim original As Object = "--" Dim rowState As DataRowState = table.Rows(i).RowState ' Attempt to retrieve the current value, which doesn't exist ' for deleted rows: If rowState <> DataRowState.Deleted Then current = table.Rows(i)("Name", DataRowVersion.Current) End If ' Attempt to retrieve the original value, which doesn't exist ' for added rows: If rowState <> DataRowState.Added Then original = table.Rows(i)("Name", DataRowVersion.Original) End If Console.WriteLine("{0}: {1}, {2} ({3})", i, _ current, original, rowState) Next End Sub Private Function GetChangedCustomers() As DataTable ' Create sample Customers table. Dim table As New DataTable ' 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() {1, "XXX"}) table.Rows.Add(New Object() {2, "XXX"}) table.Rows.Add(New Object() {3, "XXX"}) table.Rows.Add(New Object() {4, "XXX"}) table.Rows.Add(New Object() {5, "XXX"}) table.Rows.Add(New Object() {6, "XXX"}) table.AcceptChanges() Return table End Function Private Function GetCustomers() As DataTable ' Create sample Customers table. Dim table As New DataTable ' 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() {1, "Mary"}) table.Rows.Add(New Object() {2, "Andy"}) table.Rows.Add(New Object() {3, "Peter"}) table.Rows.Add(New Object() {4, "Russ"}) table.AcceptChanges() Return table End Function 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() {5}) table.Rows.Add(New Object() {6}) table.Rows.Add(New Object() {7}) table.Rows.Add(New Object() {8}) 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.Rows.Add(New Object() {"Russ"}) 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 Private Function SetupModifiedRows() As DataTable ' Fill a DataTable with customer info, and ' then modify, delete, and add rows. Dim table As DataTable = GetCustomers() ' Row 0 is unmodified. ' Row 1 is modified. ' Row 2 is deleted. ' Row 5 is added. table.Rows(1)("Name") = "Sydney" table.Rows(2).Delete() Dim row As DataRow = table.NewRow row("ID") = 5 row("Name") = "Melony" table.Rows.Add(row) ' Note that the code doesn't call ' table.AcceptChanges() Return table End Function
static void Main() { // This example examines a number of scenarios involving the // DataTable.Load method. Console.WriteLine("Load a DataTable and infer its schema:"); // The table has no schema. The Load method will infer the // schema from the IDataReader: DataTable table = new DataTable(); // Retrieve a data reader, based on the Customers data. In // an application, this data might be coming from a middle-tier // business object: DataTableReader reader = new DataTableReader(GetCustomers()); table.Load(reader); PrintColumns(table); Console.WriteLine(" ============================= "); Console.WriteLine( "Load a DataTable from an incompatible IDataReader:"); // Create a table with a single integer column. Attempt // to load data from a reader with a schema that is // incompatible. Note the exception, determined // by the particular incompatibility: table = GetIntegerTable(); reader = new DataTableReader(GetStringTable()); try { table.Load(reader); } catch (Exception ex) { Console.WriteLine(ex.GetType().Name + ":" + ex.Message); } Console.WriteLine(" ============================= "); Console.WriteLine( "Load a DataTable with an IDataReader that has extra columns:"); // Note that loading a reader with extra columns adds // the columns to the existing table, if possible: table = GetIntegerTable(); reader = new DataTableReader(GetCustomers()); table.Load(reader); PrintColumns(table); Console.WriteLine(" ============================= "); Console.WriteLine( "Load a DataTable with an IDataReader that has missing columns:"); // Note that loading a reader with missing columns causes // the columns to be filled with null data, if possible: table = GetCustomers(); reader = new DataTableReader(GetIntegerTable()); table.Load(reader); PrintColumns(table); // Demonstrate the various possibilites when loading data // into a DataTable that already contains data. Console.WriteLine(" ============================= "); Console.WriteLine("Demonstrate data considerations:"); Console.WriteLine("Current value, Original value, (RowState)"); Console.WriteLine(" ============================= "); Console.WriteLine("Original table:"); table = SetupModifiedRows(); DisplayRowState(table); Console.WriteLine(" ============================= "); Console.WriteLine("Data in IDataReader to be loaded:"); DisplayRowState(GetChangedCustomers()); // Load data into a DataTable, retrieve a DataTableReader // containing different data, and call the Load method. Console.WriteLine(" ============================= "); Console.WriteLine("table.Load(reader)"); Console.WriteLine(" ============================= "); table = SetupModifiedRows(); reader = new DataTableReader(GetChangedCustomers()); table.Load(reader); DisplayRowState(table); Console.WriteLine("Press any key to continue."); Console.ReadKey(); } private static void DisplayRowState(DataTable table) { for (int i = 0; i <= table.Rows.Count - 1; i++) { object current = "--"; object original = "--"; DataRowState rowState = table.Rows[i].RowState; // Attempt to retrieve the current value, which doesn't exist // for deleted rows: if (rowState != DataRowState.Deleted) { current = table.Rows[i]["Name", DataRowVersion.Current]; } // Attempt to retrieve the original value, which doesn't exist // for added rows: if (rowState != DataRowState.Added) { original = table.Rows[i]["Name", DataRowVersion.Original]; } Console.WriteLine("{0}: {1}, {2} ({3})", i, current, original, rowState); } } private static DataTable GetChangedCustomers() { // Create sample Customers table. DataTable table = new DataTable(); // 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[] { 1, "XXX" }); table.Rows.Add(new object[] { 2, "XXX" }); table.Rows.Add(new object[] { 3, "XXX" }); table.Rows.Add(new object[] { 4, "XXX" }); table.Rows.Add(new object[] { 5, "XXX" }); table.Rows.Add(new object[] { 6, "XXX" }); table.AcceptChanges(); return table; } private static DataTable GetCustomers() { // 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)); 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[] { 1, "Mary" }); table.Rows.Add(new object[] { 2, "Andy" }); table.Rows.Add(new object[] { 3, "Peter" }); table.Rows.Add(new object[] { 4, "Russ" }); table.AcceptChanges(); return table; } 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[] { 5 }); table.Rows.Add(new object[] { 6 }); table.Rows.Add(new object[] { 7 }); table.Rows.Add(new object[] { 8 }); 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.Rows.Add(new object[] { "Russ" }); table.AcceptChanges(); return table; } private static void PrintColumns(DataTable table) { // Loop through all the rows in the DataTableReader foreach (DataRow row in table.Rows) { for (int i = 0; i < table.Columns.Count; i++) { Console.Write(row[i] + " "); } Console.WriteLine(); } } private static DataTable SetupModifiedRows() { // Fill a DataTable with customer info, and // then modify, delete, and add rows. DataTable table = GetCustomers(); // Row 0 is unmodified. // Row 1 is modified. // Row 2 is deleted. // Row 5 is added. table.Rows[1]["Name"] = "Sydney"; table.Rows[2].Delete(); DataRow row = table.NewRow(); row["ID"] = 5; row["Name"] = "Melony"; table.Rows.Add(row); // Note that the code doesn't call // table.AcceptChanges() return table; }

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataTable.Load メソッド (IDataReader, LoadOption, FillErrorEventHandler)
アセンブリ: System.Data (system.data.dll 内)

Public Overridable Sub Load ( _ reader As IDataReader, _ loadOption As LoadOption, _ errorHandler As FillErrorEventHandler _ )
Dim instance As DataTable Dim reader As IDataReader Dim loadOption As LoadOption Dim errorHandler As FillErrorEventHandler instance.Load(reader, loadOption, errorHandler)
public virtual void Load ( IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler )
public: virtual void Load ( IDataReader^ reader, LoadOption loadOption, FillErrorEventHandler^ errorHandler )
public function Load ( reader : IDataReader, loadOption : LoadOption, errorHandler : FillErrorEventHandler )

Load メソッドでは、読み込まれた IDataReader の最初の結果セットが処理されます。処理が正常に完了したら、リーダーの位置が次の結果セット (存在する場合) に設定されます。データを変換する場合、Load メソッドでは DbDataAdapter.Fill メソッドと同じ変換規則が使用されます。
Load メソッドでは、IDataReader インスタンスからデータを読み込む際に、スキーマ、データ、イベント処理の 3 つの問題を考慮する必要があります。スキーマを使用するときに、Load メソッドで発生する可能性がある条件を次の表に示します。このスキーマの動作は、データを含まない結果セットを含め、インポートされるすべての結果セットで発生します。
DataTable にスキーマがない。 | |
Load メソッドにより、DataTable のスキーマに列が追加されます。DataTable 内にある対応する列と読み込まれた結果セットの値に互換性がなければ、このメソッドは例外をスローします。さらにこのメソッドは、追加されているすべての列の結果セットから、制約の情報を取得します。主キー制約の場合を除き、現在の DataTable で読み込み処理の開始位置に列が格納されていない場合にのみ、この制約の情報が使用されます。 | |
欠けている列に既定値が定義されているか、その列のデータ型が null 許容の場合、Load メソッドでは欠けている列を既定値または null 値に置き換えて行を追加できます。既定値がない場合や null を使用できない場合は、Load メソッドは例外をスローします。特に既定値が指定されていない場合、Load メソッドでは暗黙的な既定値として null 値が使用されます。 |
データ操作の観点から Load メソッドの動作を考える前に、各列の現在の値と元の値の両方が DataTable 内の各行で維持されることについて考えてみましょう。値は等しいこともありますが、DataTable への入力後に行内のデータが変更された場合は異なることもあります。詳細については、「行の状態とバージョン」を参照してください。
このメソッド呼び出しでは、指定された LoadOption パラメータによって受信データの処理が変化します。読み込む行に既存の行と同じ主キーが含まれている場合、Load メソッドではどのように処理するのでしょうか。現在の値を変更するのか、元の値を変更するのか、またはその両方なのでしょうか。このような問題は、loadOption パラメータを使用して解決します。
既存の行と受信した行の主キー値が対応している場合、行は現在の行の状態値を使用して処理されるか、新しい行として処理されます。
イベント処理の観点から見ると、RowChanging イベントは各行が変更される前に発生し、RowChanged イベントは各行が変更された後に発生します。どちらの場合でも、イベント ハンドラに渡される DataRowChangeEventArgs インスタンスの Action プロパティに、イベントに関連付けられている特定のアクションに関する情報が格納されます。このアクション値は、読み込み操作の前の行の状態に応じて変わります。どちらの場合でも、両方のイベントが発生し、アクションは同じになります。現在の行の状態に応じて、アクションは各行の現在のバージョンまたは元のバージョン、あるいは両方のバージョンに適用されます。
Load メソッドを LoadOption の各値を使って呼び出したときの動作を次の表に示します。また、それらの値と読み込む行の行状態との関係も示します。"(存在せず)" と表記された最後の行は、受信した行が既存の行と一致しなかった場合の動作を表します。この表の各マスに、行内のフィールドの現在の値と元の値、および Load メソッドが完了した後の値の DataRowState を示します。
既存の DataRowState | OverwriteChanges | ||
---|---|---|---|
元の値 = -<Not available> 状態 = <Added> RowAction = Change | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal | 元の値 = <Incoming> 状態 = <Modified> RowAction = ChangeOriginal | |
元の値 = <Existing> 状態 = <Modified> RowAction = Change | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal | 元の値 = <Incoming> 状態 = <Modified> RowAction = ChangeOriginal | |
現在の値 = --- 元の値 = <Existing> 状態 = <Deleted> 元の値 = <Not available> 状態 = <Added> RowAction = Add | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal | 現在の値 = <Not available> 元の値 = <Incoming> 状態 = <Deleted> RowAction = ChangeOriginal | |
元の値 = <Existing> 状態 = <Unchanged> RowAction = Nothing 状態 = <Modified> RowAction = Change | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal | |
(存在せず) | 元の値 = <Not available> 状態 = <Added> RowAction = Add | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal | 元の値 = <Incoming> 状態 = <Unchanged> RowAction = ChangeCurrentAndOriginal |
DataColumn の値は、ReadOnly や AutoIncrement などのプロパティを使用することで制約できます。Load メソッドでは、このような列を、列のプロパティで定義された動作に応じた方法で処理します。DataColumn に対する読み取り専用制約は、メモリ内で発生する変更にのみ適用されます。Load メソッドでは、必要に応じて読み取り専用列の値も上書きされます。
Load メソッドを呼び出すときに OverwriteChanges オプションまたは PreserveChanges オプションを指定した場合、受信データは DataTable の主データ ソースから受信されており、DataTable によって変更が追跡され、変更をデータ ソースに反映できることが想定されます。Upsert オプションを選択した場合、データは中間層コンポーネントから得られるデータなどの 2 次データ ソースの 1 つから受信されていることが想定されます。これはユーザーにより変更されている可能性があります。その場合、DataTable 内の 1 つ以上のデータ ソースのデータを集約した後、そのデータを主データ ソースに反映する意図があることが想定されます。主キーの比較に使用する行のバージョンを特定するために、LoadOption パラメータが使用されます。その詳細を次の表で説明します。
OverwriteChanges | |
PreserveChanges | |
errorHandler パラメータは、データの読み込み中にエラーが発生した場合に呼び出されるプロシージャを参照する FillErrorEventHandler デリゲートです。プロシージャに FillErrorEventArgs パラメータを渡すことで得られるプロパティを使用して、発生したエラー、データの現在の行、入力先の DataTable に関する情報を取得できます。単純な try/catch ブロックを使用せず、このデリゲート機構を使用することで、エラーの特定と状況の処理を行い、さらに必要であれば処理を続行できます。FillErrorEventArgs パラメータには Continue プロパティがあります。このプロパティを true に指定すると、エラーの処理後に処理を続行することが指定されます。このプロパティを false に設定すると、処理の中断が指定されます。このプロパティを false に設定すると、問題の原因となったコードによって例外がスローされるので注意してください。

Sub Main() 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: table = GetIntegerTable() Dim reader As New DataTableReader(GetStringTable()) table.Load(reader, LoadOption.OverwriteChanges, _ AddressOf FillErrorHandler) 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: DataTable table = GetIntegerTable(); DataTableReader reader = new DataTableReader(GetStringTable()); table.Load(reader, LoadOption.OverwriteChanges, FillErrorHandler); 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; }

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataTable.Load メソッド

名前 | 説明 |
---|---|
DataTable.Load (IDataReader) | 指定された IDataReader を使用し、DataTable にデータ ソースからの値を設定します。DataTable が既に行を含んでいる場合、データ ソースからの受信データは既存の行にマージされます。 .NET Compact Framework によってサポートされています。 |
DataTable.Load (IDataReader, LoadOption) | 指定された IDataReader を使用し、DataTable にデータ ソースからの値を設定します。DataTable が既に行を含んでいる場合、loadOption パラメータの値に従って、データ ソースからの受信データは既存の行にマージされます。 .NET Compact Framework によってサポートされています。 |
DataTable.Load (IDataReader, LoadOption, FillErrorEventHandler) | エラー処理デリゲートを使用し、指定された IDataReader を使用して、DataTable にデータ ソースからの値を設定します。 .NET Compact Framework によってサポートされています。 |
