DataSourceView 클래스

정의

데이터 소스 컨트롤의 기능을 정의하는 모든 데이터 소스 뷰 클래스의 기본 클래스 역할을 합니다.

public ref class DataSourceView abstract
public abstract class DataSourceView
type DataSourceView = class
Public MustInherit Class DataSourceView
상속
DataSourceView
파생

예제

다음 코드 예제를 확장 하는 방법에 설명 합니다 DataSourceView 데이터 소스 컨트롤에 대 한 강력한 형식의 뷰 클래스를 만드는 클래스입니다. 합니다 CsVDataSourceView 클래스의 기능을 정의 합니다 CsvDataSource 데이터 소스 제어 및 쉼표로 구분 된 값 (.csv) 파일에 저장 된 데이터를 사용 하는 데이터 바인딩된 컨트롤에 대 한 구현을 제공 합니다. 대 한 자세한 내용은 합니다 CsvDataSource 데이터 소스 컨트롤 참조를 DataSourceControl 클래스입니다.

// The CsvDataSourceView class encapsulates the
// capabilities of the CsvDataSource data source control.
public class CsvDataSourceView : DataSourceView
{

    public CsvDataSourceView(IDataSource owner, string name) :base(owner, DefaultViewName) {
    }

    // The data source view is named. However, the CsvDataSource
    // only supports one view, so the name is ignored, and the
    // default name used instead.
    public static string DefaultViewName = "CommaSeparatedView";

    // The location of the .csv file.
    private string sourceFile = String.Empty;
    internal string SourceFile {
        get {
            return sourceFile;
        }
        set {
            // Use MapPath when the SourceFile is set, so that files local to the
            // current directory can be easily used.
            string mappedFileName = HttpContext.Current.Server.MapPath(value);
            sourceFile = mappedFileName;
        }
    }

    // Do not add the column names as a data row. Infer columns if the CSV file does
    // not include column names.
    private bool columns = false;
    internal bool IncludesColumnNames {
        get {
            return columns;
        }
        set {
            columns = value;
        }
    }

    // Get data from the underlying data source.
    // Build and return a DataView, regardless of mode.
    protected override IEnumerable ExecuteSelect(DataSourceSelectArguments selectArgs) {
        IEnumerable dataList = null;
        // Open the .csv file.
        if (File.Exists(this.SourceFile)) {
            DataTable data = new DataTable();

            // Open the file to read from.
            using (StreamReader sr = File.OpenText(this.SourceFile)) {
                // Parse the line
                string s = "";
                string[] dataValues;
                DataColumn col;

                // Do the following to add schema.
                dataValues = sr.ReadLine().Split(',');
                // For each token in the comma-delimited string, add a column
                // to the DataTable schema.
                foreach (string token in dataValues) {
                    col = new DataColumn(token,typeof(string));
                    data.Columns.Add(col);
                }

                // Do not add the first row as data if the CSV file includes column names.
                if (! IncludesColumnNames)
                    data.Rows.Add(CopyRowData(dataValues, data.NewRow()));

                // Do the following to add data.
                while ((s = sr.ReadLine()) != null) {
                    dataValues = s.Split(',');
                    data.Rows.Add(CopyRowData(dataValues, data.NewRow()));
                }
            }
            data.AcceptChanges();
            DataView dataView = new DataView(data);
            if (!string.IsNullOrEmpty(selectArgs.SortExpression)) {
                dataView.Sort = selectArgs.SortExpression;
            }
            dataList = dataView;
        }
        else {
            throw new System.Configuration.ConfigurationErrorsException("File not found, " + this.SourceFile);
        }

        if (null == dataList) {
            throw new InvalidOperationException("No data loaded from data source.");
        }

        return dataList;
    }

    private DataRow CopyRowData(string[] source, DataRow target) {
        try {
            for (int i = 0;i < source.Length;i++) {
                target[i] = source[i];
            }
        }
        catch (System.IndexOutOfRangeException) {
            // There are more columns in this row than
            // the original schema allows.  Stop copying
            // and return the DataRow.
            return target;
        }
        return target;
    }
    // The CsvDataSourceView does not currently
    // permit deletion. You can modify or extend
    // this sample to do so.
    public override bool CanDelete {
        get {
            return false;
        }
    }
    protected override int ExecuteDelete(IDictionary keys, IDictionary values)
    {
        throw new NotSupportedException();
    }
    // The CsvDataSourceView does not currently
    // permit insertion of a new record. You can
    // modify or extend this sample to do so.
    public override bool CanInsert {
        get {
            return false;
        }
    }
    protected override int ExecuteInsert(IDictionary values)
    {
        throw new NotSupportedException();
    }
    // The CsvDataSourceView does not currently
    // permit update operations. You can modify or
    // extend this sample to do so.
    public override bool CanUpdate {
        get {
            return false;
        }
    }
    protected override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
    {
        throw new NotSupportedException();
    }
}
' The CsvDataSourceView class encapsulates the
' capabilities of the CsvDataSource data source control.

Public Class CsvDataSourceView
   Inherits DataSourceView

   Public Sub New(owner As IDataSource, name As String)
       MyBase.New(owner, DefaultViewName)
   End Sub

   ' The data source view is named. However, the CsvDataSource
   ' only supports one view, so the name is ignored, and the
   ' default name used instead.
   Public Shared DefaultViewName As String = "CommaSeparatedView"

   ' The location of the .csv file.
   Private aSourceFile As String = [String].Empty

   Friend Property SourceFile() As String
      Get
         Return aSourceFile
      End Get
      Set
         ' Use MapPath when the SourceFile is set, so that files local to the
         ' current directory can be easily used.
         Dim mappedFileName As String
         mappedFileName = HttpContext.Current.Server.MapPath(value)
         aSourceFile = mappedFileName
      End Set
   End Property

   ' Do not add the column names as a data row. Infer columns if the CSV file does
   ' not include column names.
   Private columns As Boolean = False

   Friend Property IncludesColumnNames() As Boolean
      Get
         Return columns
      End Get
      Set
         columns = value
      End Set
   End Property

   ' Get data from the underlying data source.
   ' Build and return a DataView, regardless of mode.
   Protected Overrides Function ExecuteSelect(selectArgs As DataSourceSelectArguments) _
    As System.Collections.IEnumerable
      Dim dataList As IEnumerable = Nothing
      ' Open the .csv file.
      If File.Exists(Me.SourceFile) Then
         Dim data As New DataTable()

         ' Open the file to read from.
         Dim sr As StreamReader = File.OpenText(Me.SourceFile)

         Try
            ' Parse the line
            Dim dataValues() As String
            Dim col As DataColumn

            ' Do the following to add schema.
            dataValues = sr.ReadLine().Split(","c)
            ' For each token in the comma-delimited string, add a column
            ' to the DataTable schema.
            Dim token As String
            For Each token In dataValues
               col = New DataColumn(token, System.Type.GetType("System.String"))
               data.Columns.Add(col)
            Next token

            ' Do not add the first row as data if the CSV file includes column names.
            If Not IncludesColumnNames Then
               data.Rows.Add(CopyRowData(dataValues, data.NewRow()))
            End If

            ' Do the following to add data.
            Dim s As String
            Do
               s = sr.ReadLine()
               If Not s Is Nothing Then
                   dataValues = s.Split(","c)
                   data.Rows.Add(CopyRowData(dataValues, data.NewRow()))
               End If
            Loop Until s Is Nothing

         Finally
            sr.Close()
         End Try

         data.AcceptChanges()
         Dim dataView As New DataView(data)
         If Not selectArgs.SortExpression Is String.Empty Then
             dataView.Sort = selectArgs.SortExpression
         End If
         dataList = dataView
      Else
         Throw New System.Configuration.ConfigurationErrorsException("File not found, " + Me.SourceFile)
      End If

      If dataList is Nothing Then
         Throw New InvalidOperationException("No data loaded from data source.")
      End If

      Return dataList
   End Function 'ExecuteSelect


   Private Function CopyRowData([source]() As String, target As DataRow) As DataRow
      Try
         Dim i As Integer
         For i = 0 To [source].Length - 1
            target(i) = [source](i)
         Next i
      Catch iore As IndexOutOfRangeException
         ' There are more columns in this row than
         ' the original schema allows.  Stop copying
         ' and return the DataRow.
         Return target
      End Try
      Return target
   End Function 'CopyRowData

   ' The CsvDataSourceView does not currently
   ' permit deletion. You can modify or extend
   ' this sample to do so.
   Public Overrides ReadOnly Property CanDelete() As Boolean
      Get
         Return False
      End Get
   End Property

   Protected Overrides Function ExecuteDelete(keys As IDictionary, values As IDictionary) As Integer
      Throw New NotSupportedException()
   End Function 'ExecuteDelete

   ' The CsvDataSourceView does not currently
   ' permit insertion of a new record. You can
   ' modify or extend this sample to do so.
   Public Overrides ReadOnly Property CanInsert() As Boolean
      Get
         Return False
      End Get
   End Property

   Protected Overrides Function ExecuteInsert(values As IDictionary) As Integer
      Throw New NotSupportedException()
   End Function 'ExecuteInsert

   ' The CsvDataSourceView does not currently
   ' permit update operations. You can modify or
   ' extend this sample to do so.
   Public Overrides ReadOnly Property CanUpdate() As Boolean
      Get
         Return False
      End Get
   End Property

   Protected Overrides Function ExecuteUpdate(keys As IDictionary, _
                                              values As IDictionary, _
                                              oldValues As IDictionary) As Integer
      Throw New NotSupportedException()
   End Function 'ExecuteUpdate

End Class

설명

ASP.NET 웹 서버 컨트롤에 일관 된 방식으로 데이터를 바인딩할 수 있도록 하는 데이터 바인딩 아키텍처를 지원 합니다. 데이터에 바인딩되는 웹 서버 컨트롤은 데이터 바인딩된 컨트롤과 바인딩 데이터 소스 컨트롤 이라고 하는 클래스 라고 합니다. 데이터 소스 컨트롤에서 모든 데이터 소스를 나타낼 수 있습니다: 관계형 데이터베이스, 파일, 스트림, 비즈니스 개체 및 등입니다. 데이터 소스 컨트롤에서 소스 나 기본 데이터의 형식에 관계 없이 데이터 바인딩된 컨트롤에 일관 된 방식으로 데이터를 제공 합니다.

제공 되는 데이터 소스 컨트롤을 사용 하 여 asp.net을 포함 하 여 SqlDataSource, AccessDataSource, 및 XmlDataSource, 대부분의 웹 개발 작업을 수행 하 합니다. 기본을 사용할 DataSourceControlDataSourceView 클래스 사용자 지정 데이터를 구현 하려는 경우 소스 제어 합니다.

데이터 소스 컨트롤의 조합으로 생각할 수 있습니다는 IDataSource 개체 목록과 해당 관련 데이터를 데이터 원본 뷰를 호출 합니다. 각 데이터 목록이 표시 됩니다는 DataSourceView 개체입니다. DataSourceView 클래스는 모든 데이터 원본 뷰 또는 목록 데이터 소스 컨트롤과 연결 된 데이터에 대 한 기본 클래스입니다. 데이터 원본 뷰는 데이터 소스 컨트롤의 기능을 정의 합니다. 기본 데이터 스토리지에는 하나 이상의 데이터 목록이 포함되어 있으므로 데이터 원본 컨트롤은 항상 하나 이상의 명명된 데이터 원본 보기와 연결됩니다. 데이터 소스 컨트롤에서 사용 합니다 GetViewNames 데이터를 열거 하는 메서드 원본 데이터 소스 컨트롤을 사용 하 여 현재 연결 된 뷰 및 GetView 이름으로 특정 데이터 원본 보기 인스턴스를 검색 하는 방법입니다.

모든 DataSourceView 개체를 지원 하 여 기본 데이터 원본에서 데이터를 검색 합니다 ExecuteSelect 메서드. 모든 보기에는 필요에 따라 등의 작업을 비롯 하 여 작업의 기본 집합을 지원 ExecuteInsert하십시오 ExecuteUpdate, 및 ExecuteDelete합니다. 데이터 바인딩된 컨트롤을 사용 하 여 연결된 된 데이터 소스를 검색 하 여 데이터 소스 컨트롤의 기능 보기를 검색할 수는 GetViewGetViewNames 메서드 및 디자인 타임 또는 런타임에 뷰를 쿼리하여 합니다.

생성자

DataSourceView(IDataSource, String)

DataSourceView 클래스의 새 인스턴스를 초기화합니다.

속성

CanDelete

현재 DataSourceView 개체와 연결된 DataSourceControl 개체가 ExecuteDelete(IDictionary, IDictionary) 작업을 지원하는지 여부를 나타내는 값을 가져옵니다.

CanInsert

현재 DataSourceView 개체와 연결된 DataSourceControl 개체가 ExecuteInsert(IDictionary) 작업을 지원하는지 여부를 나타내는 값을 가져옵니다.

CanPage

현재 DataSourceView 개체와 연결된 DataSourceControl 개체가 ExecuteSelect(DataSourceSelectArguments) 메서드로 검색된 데이터에 대해 페이징 작업을 지원하는지 여부를 나타내는 값을 가져옵니다.

CanRetrieveTotalRowCount

현재 DataSourceView 개체와 연결된 DataSourceControl 개체가 데이터가 아닌 총 데이터 행 수에 대한 검색을 지원하는지 여부를 나타내는 값을 가져옵니다.

CanSort

현재 DataSourceView 개체와 연결된 DataSourceControl 개체가 내부 데이터 소스에 대한 정렬된 뷰를 지원하는지 여부를 나타내는 값을 가져옵니다.

CanUpdate

현재 DataSourceView 개체와 연결된 DataSourceControl 개체가 ExecuteUpdate(IDictionary, IDictionary, IDictionary) 작업을 지원하는지 여부를 나타내는 값을 가져옵니다.

Events

데이터 소스 뷰에 대한 이벤트 처리기 대리자의 목록을 가져옵니다.

Name

소스 데이터 뷰의 이름을 가져옵니다.

메서드

CanExecute(String)

지정된 명령을 실행할 수 있는지 여부를 결정합니다.

Delete(IDictionary, IDictionary, DataSourceViewOperationCallback)

DataSourceView 개체가 나타내는 데이터 목록에서 비동기 삭제 작업을 수행합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
ExecuteCommand(String, IDictionary, IDictionary)

지정된 명령을 실행합니다.

ExecuteCommand(String, IDictionary, IDictionary, DataSourceViewOperationCallback)

지정된 명령을 실행합니다.

ExecuteDelete(IDictionary, IDictionary)

DataSourceView 개체가 나타내는 데이터의 목록에서 삭제 작업을 수행합니다.

ExecuteInsert(IDictionary)

DataSourceView 개체가 나타내는 데이터 목록에서 삽입 작업을 수행합니다.

ExecuteSelect(DataSourceSelectArguments)

내부 데이터 스토리지에서 데이터 목록을 가져옵니다.

ExecuteUpdate(IDictionary, IDictionary, IDictionary)

DataSourceView 개체가 나타내는 데이터 목록에서 업데이트 작업을 수행합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
Insert(IDictionary, DataSourceViewOperationCallback)

DataSourceView 개체가 나타내는 데이터 목록에서 비동기 삽입 작업을 수행합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OnDataSourceViewChanged(EventArgs)

DataSourceViewChanged 이벤트를 발생시킵니다.

RaiseUnsupportedCapabilityError(DataSourceCapabilities)

RaiseUnsupportedCapabilitiesError(DataSourceView) 작업을 위해 요청한 기능과 뷰가 지원하는 기능을 비교하기 위해 ExecuteSelect(DataSourceSelectArguments) 메서드에 의해 호출됩니다.

Select(DataSourceSelectArguments, DataSourceViewSelectCallback)

내부 데이터 스토리지에서 비동기적으로 데이터 목록을 가져옵니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
Update(IDictionary, IDictionary, IDictionary, DataSourceViewOperationCallback)

DataSourceView 개체가 나타내는 데이터 목록에서 비동기 업데이트 작업을 수행합니다.

이벤트

DataSourceViewChanged

데이터 소스 뷰가 변경되면 이 이벤트가 발생합니다.

적용 대상

추가 정보