DataSourceViewとは? わかりやすく解説

DataSourceView イベント


パブリック イベントパブリック イベント

  名前 説明
パブリック イベント DataSourceViewChanged データ ソース ビューが変更された場合に発生します。
参照参照

関連項目

DataSourceView クラス
System.Web.UI 名前空間
DataSourceControl クラス
HierarchicalDataSourceView

その他の技術情報

ASP.NET データ アクセスの概要
データ ソース コントロールの概要

DataSourceView クラス

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

データ ソース コントロールの機能を定義するすべてのデータ ソース ビュー クラスの基本クラスとして機能します。

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

Public MustInherit Class
 DataSourceView
Dim instance As DataSourceView
public abstract class DataSourceView
public ref class DataSourceView abstract
public abstract class DataSourceView
public abstract class DataSourceView
解説解説

ASP.NET では、Web サーバー コントロールを一貫した方式でデータにバインドできるようにするデータ バインディング アーキテクチャがサポートされています。データにバインドされる Web サーバー コントロールをデータ バインド コントロールといいます。また、そのバインディングを容易にするクラスをデータ ソース コントロールといいます。データ ソース コントロールは、リレーショナル データベース、ファイル、ストリーム、ビジネス オブジェクトなど、あらゆるデータ ソースを表すことができます。データ ソース コントロールにより、基になるデータのソースや形式にかかわらず、一貫した方式でデータがデータ バインド コントロールに提供されます。

多くの Web 開発タスクは、ASP.NET に用意されている SqlDataSource、AccessDataSource、XmlDataSource などのデータ ソース コントロールを使用して行います。独自にカスタムのデータ ソース コントロールを実装する場合は、DataSourceControl 基本クラスおよび DataSourceView 基本クラスを使用します。

データ ソース コントロールは、IDataSource オブジェクトに、そのオブジェクトに関連付けられたデータ ソース ビューと呼ばれるリストを組み合わせたものと考えることができます。データの各リストは、DataSourceView オブジェクトで表されます。DataSourceView クラスは、すべてのデータ ソース ビューの基本クラスか、データ ソース コントロールに関連付けられているデータのリストです。データ ソース ビューによって、データ ソース コントロールの機能が定義されます。基になるデータ ストレージには 1 つ以上のデータのリストが含まれているので、データ ソース コントロールは、1 つ以上の名前付きのデータ ソース ビューに常に関連付けられています。データ ソース コントロールでは、データ ソース コントロールに現在関連付けられているデータ ソース ビューが GetViewNames メソッドを使用して列挙され、特定のデータ ソース ビュー インスタンスが GetView メソッドを使用して名前を指定することにより取得されます。

基になるデータ ソースから ExecuteSelect メソッドを使用してデータを取得する操作は、すべての DataSourceView オブジェクトでサポートされています。すべてのビューでは、ExecuteInsert、ExecuteUpdate、ExecuteDelete などの操作を含む一連の基本的な操作をオプションでサポートできます。データ バインド コントロールでは、GetView メソッドおよび GetViewNames メソッドを使用して関連付けられているデータ ソース ビューを取得するか、デザイン時または実行時にデータ ソース ビューを照会することにより、データ ソース コントロールの機能を検出できます。

使用例使用例

DataSourceView クラスを拡張して、データ ソース コントロールの厳密に型指定されたビュー クラスを作成する方法を次のコード例に示します。CsVDataSourceView クラスは、CsvDataSource データ ソース コントロールの機能を定義し、コンマ区切りのファイル (.csv) に格納されたデータを使用するためのデータ バインド コントロールの実装を提供します。CsvDataSource データ ソース コントロールの詳細については、DataSourceControl クラスのトピックを参照してください。

' 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 'New

   ' 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 'CsvDataSourceView
// 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 (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;
    }
    // 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();
    }
}
.NET Framework のセキュリティ.NET Framework のセキュリティ
継承階層継承階層
System.Object
  System.Web.UI.DataSourceView
     System.Web.UI.WebControls.ObjectDataSourceView
     System.Web.UI.WebControls.SiteMapDataSourceView
     System.Web.UI.WebControls.SqlDataSourceView
     System.Web.UI.WebControls.XmlDataSourceView
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DataSourceView コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

DataSourceView クラスの新しいインスタンスを初期化します。

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

Protected Sub New ( _
    owner As IDataSource, _
    viewName As String _
)
Dim owner As IDataSource
Dim viewName As String

Dim instance As New DataSourceView(owner,
 viewName)
protected DataSourceView (
    IDataSource owner,
    string viewName
)
protected:
DataSourceView (
    IDataSource^ owner, 
    String^ viewName
)
protected DataSourceView (
    IDataSource owner, 
    String viewName
)
protected function DataSourceView (
    owner : IDataSource, 
    viewName : String
)

パラメータ

owner

DataSourceView に関連付けられているデータ ソース コントロール。

viewName

DataSourceView オブジェクトの名前。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataSourceView クラス
DataSourceView メンバ
System.Web.UI 名前空間

DataSourceView プロパティ


パブリック プロパティパブリック プロパティ

( プロテクト プロパティ も参照)
  名前 説明
パブリック プロパティ CanDelete 現在の DataSourceControl オブジェクトに関連付けられている DataSourceView オブジェクトで ExecuteDelete 操作がサポートされているかどうかを示す値を取得します。
パブリック プロパティ CanInsert 現在の DataSourceControl オブジェクトに関連付けられている DataSourceView オブジェクトで ExecuteInsert 操作がサポートされているかどうかを示す値を取得します。
パブリック プロパティ CanPage 現在の DataSourceControl オブジェクトに関連付けられている DataSourceView オブジェクトで、ExecuteSelect メソッドで取得したデータを使用するページングがサポートされているかどうかを示す値を取得します。
パブリック プロパティ CanRetrieveTotalRowCount 現在の DataSourceControl オブジェクトに関連付けられた DataSourceView オブジェクトで、データではなく行の合計数を取得する操作がサポートされているかどうかを示す値を取得します。
パブリック プロパティ CanSort 現在の DataSourceControl オブジェクトに関連付けられている DataSourceView オブジェクトで、基になるデータ ソースに対する並べ替え済みのビューがサポートされているかどうかを示す値を取得します。
パブリック プロパティ CanUpdate 現在の DataSourceControl オブジェクトに関連付けられている DataSourceView オブジェクトで ExecuteUpdate 操作がサポートされているかどうかを示す値を取得します。
パブリック プロパティ Name データ ソース ビュー名を取得します。
プロテクト プロパティプロテクト プロパティ
参照参照

関連項目

DataSourceView クラス
System.Web.UI 名前空間
DataSourceControl クラス
HierarchicalDataSourceView

その他の技術情報

ASP.NET データ アクセスの概要
データ ソース コントロールの概要

DataSourceView メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

DataSourceView クラス
System.Web.UI 名前空間
DataSourceControl クラス
HierarchicalDataSourceView

その他の技術情報

ASP.NET データ アクセスの概要
データ ソース コントロールの概要

DataSourceView メンバ

データ ソース コントロールの機能を定義するすべてのデータ ソース ビュー クラスの基本クラスとして機能します。

DataSourceView データ型で公開されるメンバを以下の表に示します。


プロテクト コンストラクタプロテクト コンストラクタ
  名前 説明
プロテクト メソッド DataSourceView DataSourceView クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
( プロテクト プロパティ も参照)
  名前 説明
パブリック プロパティ CanDelete 現在の DataSourceControl オブジェクトに関連付けられている DataSourceView オブジェクトで ExecuteDelete 操作がサポートされているかどうかを示す値を取得します。
パブリック プロパティ CanInsert 現在の DataSourceControl オブジェクトに関連付けられている DataSourceView オブジェクトで ExecuteInsert 操作がサポートされているかどうかを示す値を取得します。
パブリック プロパティ CanPage 現在の DataSourceControl オブジェクトに関連付けられている DataSourceView オブジェクトで、ExecuteSelect メソッドで取得したデータを使用するページングがサポートされているかどうかを示す値を取得します。
パブリック プロパティ CanRetrieveTotalRowCount 現在の DataSourceControl オブジェクトに関連付けられた DataSourceView オブジェクトで、データではなく行の合計数を取得する操作がサポートされているかどうかを示す値を取得します。
パブリック プロパティ CanSort 現在の DataSourceControl オブジェクトに関連付けられている DataSourceView オブジェクトで、基になるデータ ソースに対する並べ替え済みのビューがサポートされているかどうかを示す値を取得します。
パブリック プロパティ CanUpdate 現在の DataSourceControl オブジェクトに関連付けられている DataSourceView オブジェクトで ExecuteUpdate 操作がサポートされているかどうかを示す値を取得します。
パブリック プロパティ Name データ ソース ビュー名を取得します。
プロテクト プロパティプロテクト プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
パブリック イベントパブリック イベント
  名前 説明
パブリック イベント DataSourceViewChanged データ ソース ビューが変更された場合に発生します。
参照参照

関連項目

DataSourceView クラス
System.Web.UI 名前空間
DataSourceControl クラス
HierarchicalDataSourceView

その他の技術情報

ASP.NET データ アクセスの概要
データ ソース コントロールの概要


このページでは「.NET Framework クラス ライブラリ リファレンス」からDataSourceViewを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDataSourceViewを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDataSourceView を検索

英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「DataSourceView」の関連用語

DataSourceViewのお隣キーワード
検索ランキング

   

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



DataSourceViewのページの著作権

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

©2026 GRAS Group, Inc.RSS