DataSourceView.ExecuteSelect(DataSourceSelectArguments) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
기본 데이터 스토리지에서 데이터 목록을 가져옵니다.
protected public:
abstract System::Collections::IEnumerable ^ ExecuteSelect(System::Web::UI::DataSourceSelectArguments ^ arguments);
protected internal abstract System.Collections.IEnumerable ExecuteSelect(System.Web.UI.DataSourceSelectArguments arguments);
abstract member ExecuteSelect : System.Web.UI.DataSourceSelectArguments -> System.Collections.IEnumerable
Protected Friend MustOverride Function ExecuteSelect (arguments As DataSourceSelectArguments) As IEnumerable
매개 변수
- arguments
- DataSourceSelectArguments
DataSourceSelectArguments 기본 데이터 검색 이외의 데이터에 대한 작업을 요청하는 데 사용되는 A입니다.
반품
IEnumerable 기본 데이터 스토리지의 데이터 목록입니다.
예제
다음 코드 예제에서는 클래스를 확장 하는 클래스에서 ExecuteSelect 메서드를 재정의 DataSourceView 하는 방법을 보여 줍니다.
CsvDataSourceView 쉼표로 구분된 값(.csv) 파일을 열고, 한 줄씩 구문 분석하고, 데이터를 메모리에 저장할 개체와 DataView 개체를 만듭니다DataTable. 마지막으로 개체에서 정렬 식을 제공하고 DataSourceSelectArguments 개체 DataView 가 인스턴스로 IEnumerable 반환되는 경우 정렬 식이 적용됩니다. 이 코드 예제는 클래스에 제공된 더 큰 예제의 DataSourceView 일부입니다.
// 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;
}
' 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
설명
이 ExecuteSelect 메서드는 기본 데이터 저장소에서 데이터를 검색하고 개체로 IEnumerable 반환하기 위해 호출됩니다. 삽입 및 정렬과 같은 다른 작업이 지원되지 않는 경우에도 모든 데이터 원본 컨트롤은 기본 데이터 스토리지에서 데이터 검색을 지원합니다. 데이터 바인딩된 컨트롤은 이벤트 또는 DataBind 메서드 호출의 DataSourceChanged 결과로 언제든지 데이터 목록을 요청할 수 있으므로 요청 시 데이터 검색을 수행해야 합니다.