2012년 5월 5일 토요일

펌] DataSet, DataTable, DataView, BindingSource, DataSource 등등.



DataSet 클래스 ##############
이 콘텐츠는 높은 품질 표준에 맞게 수작업으로 번역된 것입니다.이 페이지와 원본 영어 콘텐츠를 동시에 보려면 "기본 설정"을 클릭하고 클래식을 보기 기본 설정으로 선택합니다.
메모리 내의 데이터 캐시를 나타냅니다.
네임스페이스:  System.Data
어셈블리:  System.Data(System.Data.dll)
구문

[SerializableAttribute]
public class DataSet : MarshalByValueComponent, IListSource, 
 IXmlSerializable, ISupportInitializeNotification, ISupportInitialize, ISerializable
설명

DataSet은 데이터 소스에서 검색한 메모리 내의 데이터 캐시이며 ADO.NET 아키텍처의 주요 구성 요소입니다.DataSet은 DataRelation개체를 통해 서로 연결할 수 있는 DataTable 개체의 컬렉션으로 구성됩니다.또한 UniqueConstraint 개체와 ForeignKeyConstraint 개체를 사용하여 DataSet에 데이터 무결성을 적용할 수 있습니다.DataSet 개체에 대한 자세한 내용은 DataSets, DataTables 및 DataViews(ADO.NET)를 참조하십시오.
DataTable 개체에는 데이터가 들어 있는 반면, DataRelationCollection을 사용하면 테이블 계층 구조를 탐색할 수 있습니다.테이블은Tables 속성을 통해 액세스되는 DataTableCollection에 포함됩니다.DataTable 개체에 액세스할 때는 조건에 따라 대/소문자가 구분됩니다.예를 들어 두 DataTable의 이름이 각각 "mydatatable"과 "Mydatatable"인 경우에는 두 테이블 중 하나를 검색하는 데 사용되는 문자열에서 대/소문자를 구분합니다.그러나 "mydatatable"은 있고 "Mydatatable"은 없는 경우에는 검색 문자열에서 대/소문자를 구분하지 않습니다.DataTable 개체 작업에 대한 자세한 내용은 DataTable 만들기(ADO.NET)를 참조하십시오.
DataSet은 데이터와 스키마를 XML 문서로 읽고 쓸 수 있습니다.이렇게 하면 데이터와 스키마를 HTTP를 통해 전송할 수 있으며 XML 사용이 가능한 모든 플랫폼의 응용 프로그램에서 사용할 수 있습니다.WriteXmlSchema 메서드를 사용하여 스��마를 XML 스키마로 저장하고 WriteXml 메서드를 사용하여 스키마와 데이터를 모두 저장할 수 있습니다.ReadXml 메서드를 사용하면 스키마와 데이터가 모두 들어 있는 XML 문서를 읽을 수 있습니다.
일반적인 다중 계층 구현에서 DataSet을 만들고 새로 고친 다음 원래 데이터를 업데이트하는 단계는 다음과 같습니다.
  1. DataSet의 각 DataTable을 빌드하고 DataAdapter를 사용하여 데이터 소스의 데이터로 채웁니다.
  2. DataRow 개체를 추가, 업데이트 또는 삭제하여 개별 DataTable 개체에서 데이터를 변경합니다.
  3. GetChanges 메서드를 호출하여 데이터만 변경한 둘째 DataSet을 만듭니다.
  4. 두 번째 DataSet을 인수로 전달하여 DataAdapter의 Update 메서드를 호출합니다.
  5. Merge 메서드를 호출하여 둘째 DataSet의 변경 내용을 첫째와 병합합니다.
  6. DataSet에서 AcceptChanges를 호출합니다.또는 RejectChanges를 호출하여 변경을 취소합니다.
참고
DataSet 및 DataTable 개체는 MarshalByValueComponent에서 상속되며 원격 서비스를 위한 ISerializable 인터페이스를 지원합니다.이 두 개체는 원격화할 수 있는 유일한 ADO.NET 개체입니다.
참고
DataSet에서 종료자가 억제되었기 때문에 DataSet에서 상속된 클래스가 가비지 수집기에 의해 종료되지 않습니다.가비지 수집기에 의해 종료될 수 있도록 파생 클래스는 해당 생성자에서 ReRegisterForFinalize 메서드를 호출할 수 있습니다.
TopicLocation
방법: 형식화된 데이터 집합 만들기Data Access in Visual Studio
연습: TreeView 컨트롤에 계층 데이터 표시Building ASP .NET Web Applications in Visual Studio
방법: 형식화된 데이터 집합 만들기Visual Studio??? ????????? ?????????
연습: TreeView 컨트롤에 계층 데이터 표시Visual Studio?????? ASP .NET ??? ?????? ???????????? ??????
방법: 형식화된 데이터 집합 만들기dv_raddata
연습: TreeView 컨트롤에 계층 데이터 표시dv_vwdcon
예제

다음 예제는 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";
        }
    }
}

상속 계층 구조

System.Object
  System.ComponentModel.MarshalByValueComponent
    System.Data.DataSet
스레드로부터의 안전성

이 형식은 다중 스레드 읽기 작업에 안전합니다.쓰기 작업을 동기화해야 합니다.

.NET Framework

4, 3.5, 3.0, 2.0, 1.1, 1.0에서 지원

.NET Framework Client Profile

4에서 지원

XNA Framework

3.0, 2.0, 1.0에서 지원
 DataTable 클래스 ##############
이 콘텐츠는 높은 품질 표준에 맞게 수작업으로 번역된 것입니다.이 페이지와 원본 영어 콘텐츠를 동시에 보려면 "기본 설정"을 클릭하고 클래식을 보기 기본 설정으로 선택합니다.
메모리에 있는 데이터로 구성된 하나의 테이블을 나타냅니다.
네임스페이스:  System.Data
어셈블리:  System.Data(System.Data.dll)
구문

[SerializableAttribute]
public class DataTable : MarshalByValueComponent, IListSource, 
 ISupportInitializeNotification, ISupportInitialize, ISerializable, IXmlSerializable
설명

DataTable은 ADO.NET 라이브러리의 중심 개체입니다.DataTable을 사용하는 다른 개체에는 DataSet 및 DataView가 포함됩니다.
DataTable 개체에 액세스할 때는 조건에 따라 대/소문자가 구분됩니다.예를 들어 두 DataTable의 이름이 각각 "mydatatable"과 "Mydatatable"인 경우에는 두 테이블 중 하나를 검색하는 데 사용되는 문자열에서 대/소문자를 구분합니다.그러나 "mydatatable"은 있고 "Mydatatable"은 없는 경우에는 검색 문자열에서 대/소문자를 구분하지 않습니다.TableName 속성 값은 동일하지만 Namespace 속성 값은 다른 두 개의 DataTable 개체가 DataSet에 포함할 수 있습니다.DataTable 개체 작업에 대한 자세한 내용은 DataTable 만들기(ADO.NET)를 참조하십시오.
프로그래밍 방식으로 DataTable을 만드는 경우 Columns 속성을 통해 액세스하는 DataColumnCollection에 DataColumn 개체를 추가하여 스키마를 먼저 정의해야 합니다.DataColumn 개체 추가에 대한 자세한 내용은 DataTable에 열 추가(ADO.NET)를 참조하십시오.
DataTable에 행을 추가하려면 먼저 NewRow 메서드를 사용하여 새 DataRow 개체를 반환해야 합니다.NewRow 메서드는 테이블의DataColumnCollection에서 정의된 DataTable의 스키마가 있는 행을 반환합니다.DataTable이 저장할 수 있는 최대 행 개수는 16,777,216입니다.자세한 내용은 DataTable에 데이터 추가를 참조하십시오.
또한 DataTable에는 데이터 무결성을 보장하는 데 사용할 수 있는 Constraint 개체의 컬렉션이 들어 있습니다.자세한 내용은 DataTable 제약 조건(ADO.NET)를 참조하십시오.
테이블이 변경될 때 이를 확인하는 데 사용할 수 있는 여러 DataTable 이벤트가 있습니다.이러한 이벤트에는 RowChanged,RowChangingRowDeleting 및 RowDeleted가 있습니다.DataTable과 함께 사용할 수 있는 이벤트에 대한 자세한 내용은 DataTable 이벤트 처리(ADO.NET)를 참조하십시오.
DataTable의 인스턴스를 만드는 경우 일부 읽기/쓰기 속성이 초기 값으로 설정됩니다.이러한 값의 목록은 DataTable.DataTable 생성자 항목을 참조하십시오.
참고
DataSet 및 DataTable 개체는 MarshalByValueComponent에서 상속되며 .NET Framework Remoting을 위한 ISerializable 인터페이스를 지원합니다.이 두 개체는 .NET Framework Remoting에 사용할 수 있는 유일한 ADO.NET 개체입니다.
TopicLocation
방법: DataTable 만들기Data Access in Visual Studio
방법: DataTable 만들기Visual Studio??? ????????? ?????????
방법: DataTable 만들기dv_raddata
예제

다음 예제에서는 두 개의 DataTable 개체와 하나의 DataRelation 개체를 만들고 해당 새 개체를 DataSet에 추가합니다.그런 다음 해당 테이블을 DataGridView 컨트롤에 표시합니다.
// Put the next line into the Declarations section.
private System.Data.DataSet dataSet;

private void MakeDataTables()
{
    // Run all of the functions. 
    MakeParentTable();
    MakeChildTable();
    MakeDataRelation();
    BindToDataGrid();
}

private void MakeParentTable()
{
    // Create a new DataTable.
    System.Data.DataTable table = new DataTable("ParentTable");
    // Declare variables for DataColumn and DataRow objects.
    DataColumn column;
    DataRow row;

    // Create new DataColumn, set DataType, 
    // ColumnName and add to DataTable.    
    column = new DataColumn();
    column.DataType = System.Type.GetType("System.Int32");
    column.ColumnName = "id";
    column.ReadOnly = true;
    column.Unique = true;
    // Add the Column to the DataColumnCollection.
    table.Columns.Add(column);

    // Create second column.
    column = new DataColumn();
    column.DataType = System.Type.GetType("System.String");
    column.ColumnName = "ParentItem";
    column.AutoIncrement = false;
    column.Caption = "ParentItem";
    column.ReadOnly = false;
    column.Unique = false;
    // Add the column to the table.
    table.Columns.Add(column);

    // Make the ID column the primary key column.
    DataColumn[] PrimaryKeyColumns = new DataColumn[1];
    PrimaryKeyColumns[0] = table.Columns["id"];
    table.PrimaryKey = PrimaryKeyColumns;

    // Instantiate the DataSet variable.
    dataSet = new DataSet();
    // Add the new DataTable to the DataSet.
    dataSet.Tables.Add(table);

    // Create three new DataRow objects and add 
    // them to the DataTable
    for (int i = 0; i<= 2; i++)
    {
        row = table.NewRow();
        row["id"] = i;
        row["ParentItem"] = "ParentItem " + i;
        table.Rows.Add(row);
    }
}

private void MakeChildTable()
{
    // Create a new DataTable.
    DataTable table = new DataTable("childTable");
    DataColumn column;
    DataRow row;

    // Create first column and add to the DataTable.
    column = new DataColumn();
    column.DataType= System.Type.GetType("System.Int32");
    column.ColumnName = "ChildID";
    column.AutoIncrement = true;
    column.Caption = "ID";
    column.ReadOnly = true;
    column.Unique = true;

    // Add the column to the DataColumnCollection.
    table.Columns.Add(column);

    // Create second column.
    column = new DataColumn();
    column.DataType= System.Type.GetType("System.String");
    column.ColumnName = "ChildItem";
    column.AutoIncrement = false;
    column.Caption = "ChildItem";
    column.ReadOnly = false;
    column.Unique = false;
    table.Columns.Add(column);

    // Create third column.
    column = new DataColumn();
    column.DataType= System.Type.GetType("System.Int32");
    column.ColumnName = "ParentID";
    column.AutoIncrement = false;
    column.Caption = "ParentID";
    column.ReadOnly = false;
    column.Unique = false;
    table.Columns.Add(column);

    dataSet.Tables.Add(table);

    // Create three sets of DataRow objects, 
    // five rows each, and add to DataTable.
    for(int i = 0; i <= 4; i ++)
    {
        row = table.NewRow();
        row["childID"] = i;
        row["ChildItem"] = "Item " + i;
        row["ParentID"] = 0 ;
        table.Rows.Add(row);
    }
    for(int i = 0; i <= 4; i ++)
    {
        row = table.NewRow();
        row["childID"] = i + 5;
        row["ChildItem"] = "Item " + i;
        row["ParentID"] = 1 ;
        table.Rows.Add(row);
    }
    for(int i = 0; i <= 4; i ++)
    {
        row = table.NewRow();
        row["childID"] = i + 10;
        row["ChildItem"] = "Item " + i;
        row["ParentID"] = 2 ;
        table.Rows.Add(row);
    }
}

private void MakeDataRelation()
{
    // DataRelation requires two DataColumn 
    // (parent and child) and a name.
    DataColumn parentColumn = 
        dataSet.Tables["ParentTable"].Columns["id"];
    DataColumn childColumn = 
        dataSet.Tables["ChildTable"].Columns["ParentID"];
    DataRelation relation = new 
        DataRelation("parent2Child", parentColumn, childColumn);
    dataSet.Tables["ChildTable"].ParentRelations.Add(relation);
}

private void BindToDataGrid()
{
    // Instruct the DataGrid to bind to the DataSet, with the 
    // ParentTable as the topmost DataTable.
    dataGrid1.SetDataBinding(dataSet,"ParentTable");
}

상속 계층 구조

System.Object
  System.ComponentModel.MarshalByValueComponent
    System.Data.DataTable
      System.Data.TypedTableBase<T>
스레드로부터의 안전성

이 형식은 다중 스레드 읽기 작업에 안전합니다.쓰기 작업을 동기화해야 합니다.
 
버전 정보

.NET Framework

4, 3.5, 3.0, 2.0, 1.1, 1.0에서 지원

.NET Framework Client Profile

4에서 지원

XNA Framework

3.0, 2.0, 1.0에서 지원
참고 항목

참조

기타 리소스

  
DataView 클래스 ##############
이 콘텐츠는 높은 품질 표준에 맞게 수작업으로 번역된 것입니다.이 페이지와 원본 영어 콘텐츠를 동시에 보려면 "기본 설정"을 클릭하고 클래식을 보기 기본 설정으로 선택합니다.
정렬, 필터링, 검색, 편집 및 탐색을 위해 데이터 바인딩할 수 있는 DataTable의 사용자 지정 뷰를 나타냅니다.
네임스페이스:  System.Data
어셈블리:  System.Data(System.Data.dll)
구문

public class DataView : MarshalByValueComponent, IBindingListView, 
 IBindingList, IList, ICollection, IEnumerable, ITypedList, 
 ISupportInitializeNotification, ISupportInitialize
설명

DataView의 주요 기능은 Windows Forms뿐만 아니라 Web Forms에서도 데이터를 바인딩할 수 있도록 하는 것입니다.
또한 DataView를 사용자 지정하여 DataTable에서 데이터의 하위 집합을 나타낼 수 있습니다.이 기능을 사용하면 두 컨트롤을 동일한DataTable에 바인딩하여 서로 다른 버전의 데이터를 표시할 수 있습니다.예를 들어, 한 컨트롤은 DataView에 바인딩하여 테이블의 모든 행을 표시하고, 다른 컨트롤은 DataTable에서 삭제된 행만 표시하도록 구성할 수 있습니다.DataTable에는 DefaultView 속성도 있습니다.이 속성은 테이블에 대한 기본 DataView를 반환합니다.예를 들어, 테이블에 대한 사용자 지정 뷰를 만들려면 DefaultView에서 반환하는 DataView에 RowFilter를 설정합니다.
필터링되고 정렬된 데이터 뷰를 만들려면 RowFilter 및 Sort 속성을 설정합니다.그런 다음 Item 속성을 사용하여 DataRowView를 하나 반환합니다.
AddNew 및 Delete 메서드를 사용하여 행 집합에 추가하거나 삭제할 수도 있습니다.이런 메서드를 사용할 때 RowStateFilter 속성을 설정하여 삭제한 행 또는 새 행만을 DataView에 표시되도록 지정할 수 있습니다.
참고
DataView에 대한 정렬 조건을 명시적으로 지정하지 않는 경우 DataView의 DataRowView 개체는DataTable.RowsDataRowCollection에서 DataView의 해당 DataRow의 인덱스에 따라 정렬됩니다.
개발자는 LINQ to DataSet을 통해 LINQ를 사용하여 DataSet에 대한 복잡하고 강력한 쿼리를 만들 수 있습니다.LINQ to DataSet 쿼리는DataRow 개체의 열거형을 반환하지만, 바인딩 시나리오에서는 쉽게 사용되지 않습니다.DataView는 LINQ to DataSet 쿼리에서 만들 수 있으며 해당 쿼리 필터링 및 정렬 특성을 사용합니다.LINQ to DataSet은 LINQ 식 기반 필터링 및 정렬을 제공하여 DataView의 기능을 확장하고 문자열 기반 필터링 및 정렬보다 훨씬 더 복잡하고 강력한 필터링 및 정렬 조작을 허용합니다. 자세한 내용은 데이터 바인딩 및 LINQ to DataSet을 참조하십시오.
예제

다음 예제에서는 한 개의 열과 다섯 개의 행이 있는 단순 DataTable을 만듭니다.두 개의 DataView 개체가 만들어지고 각 개체에RowStateFilter가 설정되어 서로 다른 테이블 데이터 뷰를 표시합니다.그런 다음 값이 출력됩니다.
private void DemonstrateDataView()
{
    // Create one DataTable with one column.
    DataTable table = new DataTable("table");
    DataColumn colItem = new DataColumn("item",
        Type.GetType("System.String"));
    table.Columns.Add(colItem);

    // Add five items.
    DataRow NewRow;
    for(int i = 0; i <5; i++)
    {
        NewRow = table.NewRow();
        NewRow["item"] = "Item " + i;
        table.Rows.Add(NewRow);
    }
    // Change the values in the table.
    table.Rows[0]["item"]="cat";
    table.Rows[1]["item"] = "dog";
    table.AcceptChanges();

    // Create two DataView objects with the same table.
    DataView firstView = new DataView(table);
    DataView secondView = new DataView(table);

    // Print current table values.
    PrintTableOrView(table,"Current Values in Table");

    // Set first DataView to show only modified 
    // versions of original rows.
    firstView.RowStateFilter=DataViewRowState.ModifiedOriginal;

    // Print values.   
    PrintTableOrView(firstView,"First DataView: ModifiedOriginal");

    // Add one New row to the second view.
    DataRowView rowView;
    rowView=secondView.AddNew();
    rowView["item"] = "fish";

    // Set second DataView to show modified versions of 
    // current rows, or New rows.
    secondView.RowStateFilter=DataViewRowState.ModifiedCurrent 
        | DataViewRowState.Added;
    // Print modified and Added rows.
    PrintTableOrView(secondView, 
        "Second DataView: ModifiedCurrent | Added");
}

private void PrintTableOrView(DataTable table, string label)
{
    // This function prints values in the table or DataView.
    Console.WriteLine("\n" + label);
    for(int i = 0; i<table.Rows.Count;i++)
    {
        Console.WriteLine("\table" + table.Rows[i]["item"]);
    }
    Console.WriteLine();
}

private void PrintTableOrView(DataView view, string label)
{

    // This overload prints values in the table or DataView.
    Console.WriteLine("\n" + label);
    for(int i = 0; i<view.Count;i++)
    {
        Console.WriteLine("\table" + view[i]["item"]);
    }
    Console.WriteLine();
}

다음 예제에서는 LINQ to DataSet 쿼리를 사용하여 총 예정 금액에 따라 정렬된 온라인 주문의 DataView를 만듭니다.
DataTable orders = dataSet.Tables["SalesOrderHeader"];

EnumerableRowCollection<DataRow> query =
    from order in orders.AsEnumerable()
    where order.Field<bool>("OnlineOrderFlag") == true
    orderby order.Field<decimal>("TotalDue")
    select order;

DataView view = query.AsDataView();

bindingSource1.DataSource = view;

상속 계층 구조

System.Object
  System.ComponentModel.MarshalByValueComponent
    System.Data.DataView
스레드로부터의 안전성

이 형식은 다중 스레드 읽기 작업에 안전합니다.쓰기 작업을 동기화해야 합니다.
 
버전 정보

.NET Framework

4, 3.5, 3.0, 2.0, 1.1, 1.0에서 지원

.NET Framework Client Profile

4에서 지원

XNA Framework

3.0, 2.0, 1.0에서 지원
참고 항목

참조

기타 리소스

  
BindingSource 클래스 ##############
참고: 이 클래스는 .NET Framework 버전 2.0에서 새로 추가되었습니다.
폼의 데이터 소스를 캡슐화합니다.
네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)
구문

public class BindingSource : Component, IBindingListView, IBindingList, IList, 
 ICollection, IEnumerable, ITypedList, ICancelAddNew, ISupportInitializeNotification, 
 ISupportInitialize, ICurrencyManagerProvider
public class BindingSource extends Component implements IBindingListView, IBindingList, 
 IList, ICollection, IEnumerable, ITypedList, ICancelAddNew, 
 ISupportInitializeNotification, ISupportInitialize, ICurrencyManagerProvider
설명

BindingSource 구성 요소는 두 가지 용도로 사용됩니다. 먼저 간접 참조 계층, 통화 관리, 변경 알림 및 기타 서비스를 제공하여 폼의 컨트롤을 데이터에 바인딩하는 과정을 단순화합니다. 이 작업은 데이터 소스에 BindingSource 구성 요소를 연결하고 폼의 컨트롤을BindingSource 구성 요소에 바인딩하는 방식으로 수행됩니다. 탐색, 정렬, 필터링 및 업데이트를 비롯한 데이터와의 추가 상호 작용은 모두 BindingSource 구성 요소를 호출하여 수행됩니다.
둘째, BindingSource 구성 요소는 강력한 형식의 데이터 소스 역할을 할 수 있습니다. 일반적으로 내부 데이터 소스의 형식은 다음 메커니즘 중 하나를 통해 고정됩니다.
  • Add 메서드를 사용하여 BindingSource 구성 요소에 항목을 추가합니다.
  • DataSource 속성을 목록, 단일 개체 또는 형식으로 설정합니다.
이 두 메커니즘은 모두 강력한 형식의 목록을 만듭니다. BindingSource에서는 DataSource 및 DataMember 속성이 나타내는 대로 단순한 데이터 바인딩과 복잡한 데이터 바인딩 모두를 지원합니다.
참고
BindingSource에서는 단순한 데이터 소스와 복잡한 데이터 소스 모두를 처리하므로 용어상의 문제가 있습니다. 이 클래스에 대한 설명에서 목록이라는 용어는 호스팅된 데이터 소스 내의 데이터 컬렉션을 나타내고 항목은 단일 요소를 나타냅니다. 복잡한 데이터 소스와 관련된 기능을 설명할 때는 같은 의미로 테이블과 행이라는 용어가 사용됩니다.
BindingSource에서는 내부 데이터에 액세스하기 위한 멤버를 제공합니다. 현재 항목은 Current 속성을 통해 검색할 수 있으며 목록 전체는 List 속성을 통해 검색할 수 있습니다. 현재 항목에 대한 편집 작업은 Current 속성과 RemoveCurrentEndEditCancelEditAdd및 AddNew 메서드를 통해 지원됩니다. 통화 관리는 모든 내부 데이터 소스 형식에 대해 자동으로 처리되지만 이 클래스는 사용자 지정할 수 있는 CurrentItemChanged 및 DataSourceChanged 등의 여러 이벤트를 노출합니다.
목록 내의 항목을 탐색하기 위해 VCR과 비슷한 UI(사용자 인터페이스)를 제공하는 BindingNavigator 클래스를 사용하여BindingSource 구성 요소에 바인딩된 데이터 소스를 탐색하거나 관리할 수도 있습니다. BindingNavigator는 모든 데이터 소스에 바인딩될 수 있지만 BindingNavigator.BindingSource 속성을 통해 BindingSource 구성 요소와 통합되도록 디자인되어 있습니다.
BindingSource 클래스의 기본 속성은 DataSource입니다. 기본 이벤트는 CurrentChanged입니다.
주의
BindingSource 클래스의 멤버는 대부분 List 속성이 나타내는 기본 목록에 대해 작동하며 단순히 해당 작업에서 기본 목록을 참조하게 합니다. 그러므로 BindingSource가 IList의 사용자 지정 구현에 바인딩된 경우 이러한 멤버의 정확한 동작은 클래스 설명서에서 설명하는 동작과 다를 수 있습니다. 예를 들어, RemoveAt 메서드는 IList.RemoveAt를 호출합니다. BindingSource 설명서에서는 기본 IList에 대한 RemoveAt 메서드가 제대로 구현된다는 이해를 바탕으로 RemoveAt 메서드를 설명합니다.
예제

다음 코드 예제에서는 BindingSource에 바인딩된 ListBox를 보여 줍니다. BindingSource는 글꼴 목록이 포함된 BindingList에 바인딩됩니다.
이 언어는 지원되지 않거나 사용할 수 있는 코드 예가 없습니다.
상속 계층 구조

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
      System.Windows.Forms.BindingSource
스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

 
버전 정보

.NET Framework

2.0에서 지원

.NET Compact Framework

2.0에서 지원
 
BindingSource.DataSource 속성 ##############
참고: 이 속성은 .NET Framework 버전 2.0에서 새로 추가되었습니다.
커넥터가 바인딩된 데이터 소스를 가져오거나 설정합니다.
네임스페이스: System.Windows.Forms 어셈블리: System.Windows.Forms(system.windows.forms.dll)
구문

public Object DataSource { get; set; }
/** @property */
public Object get_DataSource ()

/** @property */
public void set_DataSource (Object value)



속성 값

데이터 소스 역할을 하는 Object입니다. 기본값은 Null 참조(Visual Basic의 경우 Nothing)입니다.
설명

DataSource 속성은 형식, 개체 및 형식 목록을 비롯한 여러 데이터 소스로 설정될 수 있습니다. 결과 데이터 소스는 목록으로 노출됩니다. 다음 표에서는 일반적인 몇몇 데이터 소스와 결과 목록의 형식을 보여 줍니다.
DataSource 속성
결과 목록
Null 참조(Visual Basic의 경우 Nothing)
개체의 빈 IBindingList입니다. 항목을 추가하면 해당 목록이 추가된 항목의 형식으로 설정됩니다.
Null 참조(Visual Basic의 경우 Nothing)(DataMember가 설정된 경우)
지원되지 않습니다. ArgumentException이 발생합니다.
목록이 아닌 형식 또는 "T" 형식 개체
"T" 형식의 빈 IBindingList입니다.
배열 인스턴스
배열 요소가 들어 있는 IBindingList입니다.
IEnumerable 인스턴스
IEnumerable 항목이 들어 있는 IBindingList입니다.
"T" 형식이 들어 있는 목록 인스턴스
"T" 형식이 들어 있는 IBindingList 인스턴스입니다.
또한 DataSourceIListSourceITypedList 등의 다른 목록 형식으로 설정될 수 있으며 BindingSource는 이 형식을 적절하게 처리합니다. 이 경우 목록에 포함된 형식에는 기본 생성자가 있어야 합니다.
데이터 소스를 설정할 경우 제공된 참조에 하나 이상의 목록 또는 테이블이 포함되어 있으면 DataMember 속성을 바인딩할 목록을 지정하는 문자열로 설정해야 합니다. 이 속성을 설정하면 DataSourceChanged 이벤트가 발생합니다.
DataSource 속성은 BindingSource 클래스의 기본 속성입니다.
예제

다음 코드 예제에서는 BindingSource 구성 요소의 DataSource에 고객 목록을 할당합니다. 이 코드 예제는 방법: BindingSource ResetItem 메서드를 사용하여 변경 알림 발생에서 제공되는 보다 큰 예제의 일부입니다.
private void Form1_Load(System.Object sender, System.EventArgs e)
{
    // Create and populate the list of DemoCustomer objects
    // which will supply data to the DataGridView.
    List<DemoCustomer> customerList = new List<DemoCustomer>();
    customerList.Add(DemoCustomer.CreateNewCustomer());
    customerList.Add(DemoCustomer.CreateNewCustomer());
    customerList.Add(DemoCustomer.CreateNewCustomer());

    // Bind the list to the BindingSource.
    this.customersBindingSource.DataSource = customerList;

    
    // Attach the BindingSource to the DataGridView.
    this.customersDataGridView.DataSource = 
        this.customersBindingSource;
}


버전 정보

.NET Framework

2.0에서 지원

.NET Compact Framework

2.0에서 지원

DataGridView 컨트롤 개요(Windows Forms) ##############

참고
DataGridView 컨트롤은 DataGrid 컨트롤에 새로운 기능이 추가된 것으로, 이전 컨트롤을 대체합니다. 그러나 이전 버전과의 호환성 및 앞으로의 사용 가능성을 고려하여 DataGrid 컨트롤을 유지하도록 선택할 수 있습니다. 자세한 내용은 Windows Forms DataGridView 컨트롤과 DataGrid 컨트롤의 차이점을 참조하십시오.
DataGridView 컨트롤을 사용하면 여러 종류의 데이터 소스에서 가져온 표 형식의 데이터를 표시하고 편집할 수 있습니다.
데이터를 DataGridView 컨트롤에 바인딩하는 작업은 많은 경우에 DataSource 속성을 설정하는 작업과 마찬가지로 단순합니다. 여러 목록이나 표가 포함된 데이터 소스에 바인딩하는 경우에는 DataMember 속성을 바인딩할 목록이나 표를 지정하는 문자열로 설정합니다.
DataGridView 컨트롤은 표준 Windows Forms 데이터 바인딩 모델을 지원하므로 다음 목록에 설명된 클래스의 인스턴스에 바인딩됩니다.
DataGridView 컨트롤을 사용하면 반환된 개체에 구현된 경우 이러한 인터페이스에서 반환된 개체의 공용 속성이나 ICustomTypeDescriptor 인터페이스에서 반환된 속성 컬렉션에 데이터를 바인딩할 수 있습니다.
일반적으로 BindingSource 구성 요소에 바인딩한 다음 BindingSource 구성 요소를 다른 데이터 소스에 바인딩하거나 비즈니스 개체로 구성 요소를 채웁니다. BindingSource 구성 요소는 다양한 데이터 소스에 바인딩할 수 있고 많은 데이터 바인딩 문제를 자동으로 해결할 수 있기 때문에 데이터 소스로 많이 사용됩니다. 자세한 내용은 BindingSource 구성 요소를 참조하십시오.
DataGridView 컨트롤은 내부 데이터 저장소 없이 바인딩되지 않은 모드에서도 사용할 수 있습니다. 바인딩되지 않은 DataGridView 컨트롤을 사용하는 코드 예제는 연습: 바인딩되지 않은 Windows Forms DataGridView 컨트롤 만들기를 참조하십시오.
DataGridView 컨트롤은 매우 다양하게 구성하고 확장할 수 있으며, 모양과 동작을 사용자 지정할 수 있는 여러 가지 속성, 메서드 및 이벤트를 제공합니다. Windows Forms 응용 프로그램에서 표 형식의 데이터를 표시하려면 DataGrid 등의 다른 컨트롤을 사용하기 전에 DataGridView 컨트롤을 먼저 사용하는 것이 좋습니다. 읽기 전용 값으로 채워진 작은 표를 표시하거나 수 백만 개의 레코드가 들어 있는 테이블을 사용자가 편집할 수 있도록 하려는 경우에 DataGridView 컨트롤을 프로그래밍하기 쉽고 메모리 효율적인 솔루션으로 사용할 수 있습니다.
단원 내용

DataGridView 컨트롤 기술 요약(Windows Forms)
DataGridView 컨트롤 개념과 관련 클래스의 사용 방법을 요약합니다.
DataGridView 컨트롤 아키텍처(Windows Forms)
DataGridView 컨트롤의 아키텍처, 형식 계층 구조 및 상속 구조를 설명합니다.
DataGridView 컨트롤 시나리오(Windows Forms)
DataGridView 컨트롤이 가장 일반적으로 사용되는 시나리오를 설명합니다.
DataGridView 컨트롤 코드 디렉터리(Windows Forms)
다양한 DataGridView 작업에 대한 설명서에 포함된 코드 예제를 볼 수 있는 링크를 제공합니다. 이러한 예제는 작업 형식별로 분류됩니다.
관련 단원

Windows Forms DataGridView 컨트롤의 열 형식
정보를 표시하고 사용자가 정보를 수정하거나 추가할 수 있도록 하는 데 사용되는 Windows Forms DataGridView 컨트롤의 열 형식을 설명합니다.
Windows Forms DataGridView 컨트롤에서 데이터 표시
컨트롤에 수동으로 데이터를 채우거나 외부 데이터 소스의 데이터로 컨트롤을 채우는 방법을 설명하는 항목을 제공합니다.
Windows Forms DataGridView 컨트롤 사용자 지정
DataGridView 셀 및 행을 사용자 지정 방식으로 그리는 방법과 파생 셀, 열 및 행 형식을 만드는 방법을 설명하는 항목을 제공합니다.
Windows Forms DataGridView 컨트롤의 성능 조정
많은 양의 데이터 작업을 수행할 때 컨트롤을 효율적으로 사용하여 성능 문제를 방지하는 방법을 설명하는 항목을 제공합니다.
참고 항목

작업

참조

개념

기타 리소스

 
private void BindData() { customersDataGridView.AutoGenerateColumns = true; customersDataGridView.DataSource = customersDataSet; customersDataGridView.DataMember = "Customers"; }
  
DataAdapter 클래스 ##############
이 콘텐츠는 높은 품질 표준에 맞게 수작업으로 번역된 것입니다.이 페이지와 원본 영어 콘텐츠를 동시에 보려면 "기본 설정"을 클릭하고 클래식을 보기 기본 설정으로 선택합니다.
DataSet을 채우고 데이터 소스를 업데이트하는 데 사용되는 SQL 명령 집합 및 데이터베이스 연결을 나타냅니다.
네임스페이스:  System.Data.Common
어셈블리:  System.Data(System.Data.dll)
구문

public class DataAdapter : Component, 
 IDataAdapter
설명

DataAdapter는 DataSet 및 데이터 소스를 연결시키는 역할을 하며 데이터를 검색하고 저장하는 데 사용됩니다.DataAdapterDataSet에 포함된 데이터를 변경하여 데이터 소스의 데이터와 일치하도록 하는 Fill과, 데이터 소스에 포함된 데이터를 변경하여DataSet의 데이터와 일치하도록 하는 Update를 매핑하여 이러한 연결을 제공합니다.
SQL Server 데이터베이스에 연결하는 경우, SqlDataAdapter를 관련 SqlCommand 및 SqlConnection 개체와 함께 사용하여 전반적인 성능을 향상시킬 수 있습니다.OLE DB 지원 데이터 소스의 경우, DataAdapter를 관련 OleDbCommand 및 OleDbConnection 개체와 함께 사용합니다.ODBC 지원 데이터 소스의 경우, DataAdapter를 관련 OdbcCommand 및 OdbcConnection 개체와 함께 사용합니다.Oracle 데이터베이스의 경우, DataAdapter를 관련 OracleCommand 및 OracleConnection 개체와 함께 사용합니다.
DataAdapter의 인스턴스가 만들어지면, 읽기/쓰기 속성이 초기 값으로 설정됩니다.이러한 값에 대한 목록은 DataAdapter 생성자를 참조하십시오.
상속 계층 구조

System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      System.Data.Common.DataAdapter
        System.Data.Common.DbDataAdapter
스레드로부터의 안전성

이 형식의 모든 공용 static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.
 
버전 정보

.NET Framework

4, 3.5, 3.0, 2.0, 1.1, 1.0에서 지원

.NET Framework Client Profile

4에서 지원

XNA Framework

3.0, 2.0, 1.0에서 지원

댓글 없음:

댓글 쓰기

국정원의 댓글 공작을 지탄합니다.

UPBIT is a South Korean company, and people died of suicide cause of coin investment.

 UPBIT is a South Korean company, and people died of suicide cause of coin. The company helps the people who control the market price manipu...