DataSourceView.ExecuteSelect メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataSourceView.ExecuteSelect メソッドの意味・解説 

DataSourceView.ExecuteSelect メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

基になるデータ ストレージからデータリスト取得します

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Protected Friend MustOverride
 Function ExecuteSelect ( _
    arguments As DataSourceSelectArguments _
) As IEnumerable
Dim arguments As DataSourceSelectArguments
Dim returnValue As IEnumerable

returnValue = Me.ExecuteSelect(arguments)
protected internal abstract IEnumerable ExecuteSelect (
    DataSourceSelectArguments arguments
)
protected public:
virtual IEnumerable^ ExecuteSelect (
    DataSourceSelectArguments^ arguments
) abstract
protected abstract IEnumerable ExecuteSelect (
    DataSourceSelectArguments arguments
)
protected internal abstract function
 ExecuteSelect (
    arguments : DataSourceSelectArguments
) : IEnumerable

パラメータ

arguments

基本的なデータ取得超えたデータ操作要求する場合使用する DataSourceSelectArguments。

戻り値
基になるデータ ストレージデータ構成される IEnumerable リスト

解説解説
使用例使用例

DataSourceView クラス拡張するクラスで、ExecuteSelect メソッドオーバーライドする方法次のコード例示しますCsvDataSourceViewコンマ区切りファイル (.csv) を開いて 1 行ず解析しメモリ内でデータ保持するために DataTable オブジェクトと DataView オブジェクト作成します最後に並べ替え式が DataSourceSelectArguments オブジェクト指定されている場合にはその並べ替え式を適用しDataView オブジェクトIEnumerable インスタンスとして返します。このコード例は、DataSourceView クラストピック取り上げているコード例一部分です。

' 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
// 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 (selectArgs.SortExpression != String.Empty) {
            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;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataSourceView クラス
DataSourceView メンバ
System.Web.UI 名前空間
CanSort



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

DataSourceView.ExecuteSelect メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataSourceView.ExecuteSelect メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS