DataSet 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
데이터의 메모리 내 캐시를 나타냅니다.
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
[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
[<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
type DataSet = class
inherit MarshalByValueComponent
interface IListSource
interface ISupportInitialize
interface ISupportInitializeNotification
interface ISerializable
interface 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
설명
이 API에 대한 자세한 내용은 DataSet에 대한 추가 API 비고를 참조하세요.
생성자
| Name | Description |
|---|---|
| DataSet() |
DataSet 클래스의 새 인스턴스를 초기화합니다. |
| DataSet(SerializationInfo, StreamingContext, Boolean) |
직렬화된 데이터를 사용하여 클래스의 새 인스턴스를 DataSet 초기화합니다. |
| DataSet(SerializationInfo, StreamingContext) |
직렬화된 데이터를 사용하여 클래스의 새 인스턴스를 DataSet 초기화합니다. |
| DataSet(String) |
지정된 이름을 사용하여 클래스의 DataSet 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| 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 |
원격 중에 사용되는 serialization 형식을 DataSet 가져오거나 설정합니다. |
| SchemaSerializationMode |
에 대한 SchemaSerializationModea를 DataSet 가져오거나 설정합니다. |
| Site | |
| Tables |
에 포함된 DataSet테이블의 컬렉션을 가져옵니다. |
메서드
이벤트
| Name | Description |
|---|---|
| Disposed |
구성 요소에서 이벤트를 수신 대기하는 Disposed 이벤트 처리기를 추가합니다. (다음에서 상속됨 MarshalByValueComponent) |
| Initialized |
초기화된 후에 DataSet 발생합니다. |
| MergeFailed |
대상과 원본 DataRow 의 기본 키 값이 같고 EnforceConstraints true로 설정된 경우에 발생합니다. |
명시적 인터페이스 구현
| Name | Description |
|---|---|
| IListSource.ContainsListCollection |
이 멤버에 대한 설명은 을 참조하세요 ContainsListCollection. |
| IListSource.GetList() |
이 멤버에 대한 설명은 을 참조하세요 GetList(). |
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
serialize 정보 개체를 serialize DataSet하는 데 필요한 데이터로 채웁니다. |
| IXmlSerializable.GetSchema() |
이 멤버에 대한 설명은 을 참조하세요 GetSchema(). |
| IXmlSerializable.ReadXml(XmlReader) |
이 멤버에 대한 설명은 을 참조하세요 ReadXml(XmlReader). |
| IXmlSerializable.WriteXml(XmlWriter) |
이 멤버에 대한 설명은 을 참조하세요 WriteXml(XmlWriter). |
적용 대상
스레드 보안
이 형식은 다중 스레드 읽기 작업에 안전합니다. 모든 쓰기 작업을 동기화해야 합니다.