DataSet クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
データのメモリ内キャッシュを表します。
public ref class DataSet : System::ComponentModel::MarshalByValueComponent, System::ComponentModel::IListSource, System::ComponentModel::ISupportInitialize, System::ComponentModel::ISupportInitializeNotification, System::Runtime::Serialization::ISerializable, System::Xml::Serialization::IXmlSerializable
public ref class DataSet : System::ComponentModel::MarshalByValueComponent, System::ComponentModel::IListSource, System::ComponentModel::ISupportInitialize, System::Runtime::Serialization::ISerializable, System::Xml::Serialization::IXmlSerializable
public ref class DataSet : System::ComponentModel::MarshalByValueComponent, System::ComponentModel::IListSource, System::ComponentModel::ISupportInitializeNotification, System::Runtime::Serialization::ISerializable, System::Xml::Serialization::IXmlSerializable
public class DataSet : System.ComponentModel.MarshalByValueComponent, System.ComponentModel.IListSource, System.ComponentModel.ISupportInitialize, System.ComponentModel.ISupportInitializeNotification, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
[System.Serializable]
public class DataSet : System.ComponentModel.MarshalByValueComponent, System.ComponentModel.IListSource, System.ComponentModel.ISupportInitialize, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
[System.Serializable]
public class DataSet : System.ComponentModel.MarshalByValueComponent, System.ComponentModel.IListSource, System.ComponentModel.ISupportInitializeNotification, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
public class DataSet : System.ComponentModel.MarshalByValueComponent, System.ComponentModel.IListSource, System.ComponentModel.ISupportInitializeNotification, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
type DataSet = class
inherit MarshalByValueComponent
interface IListSource
interface ISupportInitialize
interface ISupportInitializeNotification
interface ISerializable
interface IXmlSerializable
[<System.Serializable>]
type DataSet = class
inherit MarshalByValueComponent
interface IListSource
interface IXmlSerializable
interface ISupportInitialize
interface ISerializable
[<System.Serializable>]
type DataSet = class
inherit MarshalByValueComponent
interface IListSource
interface IXmlSerializable
interface ISupportInitializeNotification
interface ISupportInitialize
interface ISerializable
[<System.Serializable>]
type DataSet = class
inherit MarshalByValueComponent
interface IListSource
interface IXmlSerializable
interface ISupportInitializeNotification
interface ISerializable
interface ISupportInitialize
Public Class DataSet
Inherits MarshalByValueComponent
Implements IListSource, ISerializable, ISupportInitialize, ISupportInitializeNotification, IXmlSerializable
Public Class DataSet
Inherits MarshalByValueComponent
Implements IListSource, ISerializable, ISupportInitialize, IXmlSerializable
Public Class DataSet
Inherits MarshalByValueComponent
Implements IListSource, ISerializable, ISupportInitializeNotification, IXmlSerializable
- 継承
- 属性
- 実装
例
次の例は、Northwind データベースから を組み合わせて作成および入力DataSetするいくつかのメソッドで構成されています。
using System;
using System.Data;
using System.Data.SqlClient;
namespace Microsoft.AdoNet.DataSetDemo
{
class NorthwindDataSet
{
static void Main()
{
string connectionString = GetConnectionString();
ConnectToData(connectionString);
}
private static void ConnectToData(string connectionString)
{
//Create a SqlConnection to the Northwind database.
using (SqlConnection connection =
new SqlConnection(connectionString))
{
//Create a SqlDataAdapter for the Suppliers table.
SqlDataAdapter adapter = new SqlDataAdapter();
// A table mapping names the DataTable.
adapter.TableMappings.Add("Table", "Suppliers");
// Open the connection.
connection.Open();
Console.WriteLine("The SqlConnection is open.");
// Create a SqlCommand to retrieve Suppliers data.
SqlCommand command = new SqlCommand(
"SELECT SupplierID, CompanyName FROM dbo.Suppliers;",
connection);
command.CommandType = CommandType.Text;
// Set the SqlDataAdapter's SelectCommand.
adapter.SelectCommand = command;
// Fill the DataSet.
DataSet dataSet = new DataSet("Suppliers");
adapter.Fill(dataSet);
// Create a second Adapter and Command to get
// the Products table, a child table of Suppliers.
SqlDataAdapter productsAdapter = new SqlDataAdapter();
productsAdapter.TableMappings.Add("Table", "Products");
SqlCommand productsCommand = new SqlCommand(
"SELECT ProductID, SupplierID FROM dbo.Products;",
connection);
productsAdapter.SelectCommand = productsCommand;
// Fill the DataSet.
productsAdapter.Fill(dataSet);
// Close the connection.
connection.Close();
Console.WriteLine("The SqlConnection is closed.");
// Create a DataRelation to link the two tables
// based on the SupplierID.
DataColumn parentColumn =
dataSet.Tables["Suppliers"].Columns["SupplierID"];
DataColumn childColumn =
dataSet.Tables["Products"].Columns["SupplierID"];
DataRelation relation =
new System.Data.DataRelation("SuppliersProducts",
parentColumn, childColumn);
dataSet.Relations.Add(relation);
Console.WriteLine(
"The {0} DataRelation has been created.",
relation.RelationName);
}
}
static private string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file.
return "Data Source=(local);Initial Catalog=Northwind;"
+ "Integrated Security=SSPI";
}
}
}
Option Explicit On
Option Strict On
Imports System.Data
Imports system.Data.SqlClient
Public Class NorthwindDataSet
Public Shared Sub Main()
Dim connectionString As String = _
GetConnectionString()
ConnectToData(connectionString)
End Sub
Private Shared Sub ConnectToData( _
ByVal connectionString As String)
' Create a SqlConnection to the Northwind database.
Using connection As SqlConnection = New SqlConnection( _
connectionString)
' Create a SqlDataAdapter for the Suppliers table.
Dim suppliersAdapter As SqlDataAdapter = _
New SqlDataAdapter()
' A table mapping names the DataTable.
suppliersAdapter.TableMappings.Add("Table", "Suppliers")
' Open the connection.
connection.Open()
Console.WriteLine("The SqlConnection is open.")
' Create a SqlCommand to retrieve Suppliers data.
Dim suppliersCommand As New SqlCommand( _
"SELECT SupplierID, CompanyName FROM dbo.Suppliers;", _
connection)
suppliersCommand.CommandType = CommandType.Text
' Set the SqlDataAdapter's SelectCommand.
suppliersAdapter.SelectCommand = suppliersCommand
' Fill the DataSet.
Dim dataSet As New DataSet("Suppliers")
suppliersAdapter.Fill(dataSet)
' Create a second SqlDataAdapter and SqlCommand to get
' the Products table, a child table of Suppliers.
Dim productsAdapter As New SqlDataAdapter()
productsAdapter.TableMappings.Add("Table", "Products")
Dim productsCommand As New SqlCommand( _
"SELECT ProductID, SupplierID FROM dbo.Products;", _
connection)
productsAdapter.SelectCommand = productsCommand
' Fill the DataSet.
productsAdapter.Fill(dataSet)
' Close the connection.
connection.Close()
Console.WriteLine("The SqlConnection is closed.")
' Create a DataRelation to link the two tables
' based on the SupplierID.
Dim parentColumn As DataColumn = _
dataSet.Tables("Suppliers").Columns("SupplierID")
Dim childColumn As DataColumn = _
dataSet.Tables("Products").Columns("SupplierID")
Dim relation As New DataRelation("SuppliersProducts", _
parentColumn, childColumn)
dataSet.Relations.Add(relation)
Console.WriteLine( _
"The {0} DataRelation has been created.", _
relation.RelationName)
End Using
End Sub
Private Shared Function GetConnectionString() As String
' To avoid storing the connection string in your code,
' you can retrieve it from a configuration file.
Return "Data Source=(local);Initial Catalog=Northwind;" _
& "Integrated Security=SSPI;"
End Function
End Class
注釈
DataSetデータ ソースから取得されたデータのメモリ内キャッシュである は、ADO.NET アーキテクチャの主要なコンポーネントです。 は DataSet 、オブジェクトと相互に関連付けることができるオブジェクトの DataTable コレクションで DataRelation 構成されます。 オブジェクトと ForeignKeyConstraint オブジェクトを使用して、 でDataSetデータの整合性をUniqueConstraint適用することもできます。 オブジェクトの DataSet 操作の詳細については、「 DataSets、DataTables、DataViews」を参照してください。
オブジェクトにはデータが含まれているのに対 DataTable し、 DataRelationCollection ではテーブル階層を移動できます。 テーブルは、 プロパティを DataTableCollection 介してアクセスされる に Tables 含まれています。 オブジェクトにアクセスするときは DataTable 、条件付きで大文字と小文字が区別されることに注意してください。 たとえば、1 つが DataTable "mydatatable" という名前で、もう 1 つが "Mydatatable" という名前の場合、テーブルの 1 つを検索するために使用される文字列は大文字と小文字が区別されます。 ただし、"mydatatable" が存在し、"Mydatatable" が存在しない場合、検索文字列は大文字と小文字は区別されません。 オブジェクトの DataTable 操作の詳細については、「 DataTable の作成」を参照してください。
では DataSet 、データとスキーマを XML ドキュメントとして読み書きできます。 その後、データとスキーマを HTTP 経由で転送し、XML 対応の任意のプラットフォーム上の任意のアプリケーションで使用できます。 メソッドを使用してスキーマを XML スキーマとして保存でき、 メソッドを WriteXmlSchema 使用してスキーマとデータの両方を WriteXml 保存できます。 スキーマとデータの両方を含む XML ドキュメントを読み取る場合は、 メソッドを使用します ReadXml 。
一般的な複数層実装では、 を作成して更新 DataSetし、次に元のデータを更新する手順は次のとおりです。
を使用してDataAdapter、 をDataSet作成し、データ ソースからのデータを に格納DataTableします。
オブジェクトを追加、更新、または削除して、個々 DataTable のオブジェクトのデータを DataRow 変更します。
メソッドを GetChanges 呼び出して、データに対する変更のみを特徴とする秒 DataSet を作成します。
の メソッドをUpdate呼び出し、2 番目DataSetの メソッドDataAdapterを引数として渡します。
で を AcceptChanges 呼び出します DataSet。 または、 を呼び出 RejectChanges して変更を取り消します。
Note
オブジェクトと DataTable オブジェクトは DataSet からMarshalByValueComponent継承され、リモート処理のインターフェイスがISerializableサポートされます。 これらは、リモート処理ができる唯一の ADO.NET オブジェクトです。
Note
から継承された DataSet クラスは、ファイナライザーが で DataSet抑制されているため、ガベージ コレクターによって最終処理されません。 派生クラスは、そのコンストラクターで メソッドを ReRegisterForFinalize 呼び出して、 クラスをガベージ コレクターによって終了させることができます。
セキュリティの考慮事項
DataSet と DataTable のセキュリティの詳細については、「 セキュリティ ガイダンス」を参照してください。
コンストラクター
DataSet() |
DataSet クラスの新しいインスタンスを初期化します。 |
DataSet(SerializationInfo, StreamingContext) |
互換性のために残されています。
シリアル化したデータを使用して、DataSet クラスの新しいインスタンスを初期化します。 |
DataSet(SerializationInfo, StreamingContext, Boolean) |
互換性のために残されています。
シリアル化したデータを使用して、DataSet クラスの新しいインスタンスを初期化します。 |
DataSet(String) |
指定された名前を使用して、DataSet クラスの新しいインスタンスを初期化します。 |
プロパティ
CaseSensitive |
DataTable オブジェクト内の文字列比較で大文字と小文字を区別するかどうかを示す値を取得または設定します。 |
Container |
コンポーネントを格納するコンテナーを取得します。 (継承元 MarshalByValueComponent) |
DataSetName |
現在の DataSet の名前を取得または設定します。 |
DefaultViewManager |
カスタム DataSet を使用してフィルター処理、検索、移動の各操作を行うことができる、DataViewManager に格納されているデータのカスタム ビューを取得します。 |
DesignMode |
コンポーネントが現在デザイン モードかどうかを示す値を取得します。 (継承元 MarshalByValueComponent) |
EnforceConstraints |
更新操作を試みたときに操作が制約規則に従っているかどうかを示す値を取得または設定します。 |
Events |
コンポーネントに結び付けられているイベント ハンドラーのリストを取得します。 (継承元 MarshalByValueComponent) |
ExtendedProperties |
|
HasErrors | |
IsInitialized |
DataSet が初期化されているかどうかを示す値を取得します。 |
Locale |
テーブル内の文字列の比較に使用するロケール情報を取得または設定します。 |
Namespace |
DataSet の名前空間を取得または設定します。 |
Prefix |
DataSet の名前空間に別名を付ける XML プリフィックスを取得または設定します。 |
Relations |
テーブルをリンクし、親テーブルから子テーブルへ移動できるようにするリレーションシップのコレクションが取得されます。 |
RemotingFormat |
リモート処理中に使用される のシリアル化形式を DataSet 取得または設定します。 |
SchemaSerializationMode |
SchemaSerializationMode の DataSet を取得または設定します。 |
Site | |
Tables |
DataSet に格納されているテーブルのコレクションを取得します。 |
メソッド
イベント
Disposed |
コンポーネントの Disposed イベントを待機するイベント ハンドラーを追加します。 (継承元 MarshalByValueComponent) |
Initialized |
DataSet が初期化された後に発生します。 |
MergeFailed |
ターゲットとソースの DataRow に同じ主キー値が格納されていて、EnforceConstraints が true に設定されているときに発生します。 |
明示的なインターフェイスの実装
IListSource.ContainsListCollection |
このメンバーの詳細については、「ContainsListCollection」をご覧ください。 |
IListSource.GetList() |
このメンバーの詳細については、「GetList()」をご覧ください。 |
ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
シリアル化情報オブジェクトを、DataSet のシリアル化に必要なデータで事前設定します。 |
IXmlSerializable.GetSchema() |
このメンバーの詳細については、「GetSchema()」をご覧ください。 |
IXmlSerializable.ReadXml(XmlReader) |
このメンバーの詳細については、「ReadXml(XmlReader)」をご覧ください。 |
IXmlSerializable.WriteXml(XmlWriter) |
このメンバーの詳細については、「WriteXml(XmlWriter)」をご覧ください。 |
適用対象
スレッド セーフ
この型は、マルチスレッド読み取り操作に対して安全です。 すべての書き込み操作を同期する必要があります。
こちらもご覧ください
フィードバック
フィードバックの送信と表示