ParameterCollection クラス

定義

高度なデータ バインディング シナリオでデータ ソース コントロールによって使用される、Parameter および Parameter 派生オブジェクトのコレクションを表します。

public ref class ParameterCollection : System::Web::UI::StateManagedCollection
public class ParameterCollection : System.Web.UI.StateManagedCollection
type ParameterCollection = class
    inherit StateManagedCollection
Public Class ParameterCollection
Inherits StateManagedCollection
継承
ParameterCollection

次のコード例では、コントロールと をAccessDataSourceFormParameter使用して、コントロール内の Microsoft Access データベースの情報を表示する方法をGridView示します。 オブジェクトは FormParameter 、 メソッドを SelectParameters 使用してコレクションに Add 追加されます。

重要

この例には、ユーザー入力を受け付けるテキスト ボックスがあります。これにより、セキュリティが脆弱になる可能性があります。 既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。 詳細については、「スクリプトによる攻略の概要」を参照してください。

<%@Page  Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

void Page_Load(Object sender, EventArgs e){

  // You can add a FormParameter to the AccessDataSource control's
  // SelectParameters collection programmatically.
  AccessDataSource1.SelectParameters.Clear();

  // Security Note: The AccessDataSource uses a FormParameter,
  // Security Note: which does not perform validation of input from the client.
  // Security Note: To validate the value of the FormParameter,
  // Security Note: handle the Selecting event.

  FormParameter formParam = new FormParameter("lastname","LastNameBox");
  formParam.Type=TypeCode.String;
  AccessDataSource1.SelectParameters.Add(formParam);
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:accessdatasource
          id="AccessDataSource1"
          runat="server"
          datasourcemode="DataSet"
          datafile="Northwind.mdb"
          selectcommand="SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate
                         FROM Orders WHERE EmployeeID =
                         (SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
      </asp:accessdatasource>

      <br />Enter the name "Davolio" or "King" in the text box and click the button.

      <br />
      <asp:textbox
        id="LastNameBox"
        runat="server" />

      <br />
      <asp:button
        id="Button1"
        runat="server"
        text="Get Records" />

      <br />
      <asp:gridview
          id="GridView1"
          runat="server"
          allowsorting="True"
          datasourceid="AccessDataSource1">
      </asp:gridview>

    </form>
  </body>
</html>
<%@Page  Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Private Sub Page_Load(sender As Object, e As EventArgs)

  ' You can add a FormParameter to the AccessDataSource control's
  ' SelectParameters collection programmatically.
  AccessDataSource1.SelectParameters.Clear()

  ' Security Note: The AccessDataSource uses a FormParameter,
  ' Security Note: which does not perform validation of input from the client.
  ' Security Note: To validate the value of the FormParameter,
  ' Security Note: handle the Selecting event.

  Dim formParam As New FormParameter("lastname","LastNameBox")
  formParam.Type=TypeCode.String
  AccessDataSource1.SelectParameters.Add(formParam)
End Sub ' Page_Load

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:accessdatasource
          id="AccessDataSource1"
          runat="server"
          datasourcemode="DataSet"
          datafile="Northwind.mdb"
          selectcommand="SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate
                         FROM Orders WHERE EmployeeID =
                         (SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
      </asp:accessdatasource>

      <br />Enter the name "Davolio" or "King" in the text box and click the button.

      <br />
      <asp:textbox
        id="LastNameBox"
        runat="server" />

      <br />
      <asp:button
        id="Button1"
        runat="server"
        text="Get Records" />

      <br />
      <asp:gridview
          id="GridView1"
          runat="server"
          allowsorting="True"
          datasourceid="AccessDataSource1">
      </asp:gridview>

    </form>
  </body>
</html>

注釈

クラスは ParameterCollection 、データ ソース コントロールを使用する高度なデータ バインディング シナリオで使用されるオブジェクトのコレクション Parameter を表します。 オブジェクトは Parameter 、ローカル Page 変数、HTTP Cookie、セッション変数、およびその他のコントロールの値に含まれる値を、データの取得、更新、削除、および挿入時にデータ ソース コントロールにバインドするために使用されます。

クラスを ParameterCollection 使用して、一連の Parameter オブジェクトをプログラムで管理します。 クラスの適切なメソッドParameterCollectionを使用して、オブジェクトを追加、挿入、および削除Parameterできます。 プログラムによってコレクションからオブジェクトを取得 Parameter するには、次のいずれかの方法を使用します。

  • インデクサーを使用して、名前または配列表記を使用して、コレクションから 1 つの Parameter オブジェクトを取得します。

  • メソッドを GetEnumerator 使用して-implemented オブジェクトを System.Collections.IEnumerator作成し、それを使用してコレクションから項目を取得できます。

プロパティは Count 、コレクション内の項目の合計数を指定し、コレクションの上限を決定するために使用されます。 、および の各メソッドを使用して、コレクションの項目をAddInsertRemove追加およびRemoveAt削除できます。

特定のデータ ソース コントロールの実装とセマンティクスによっては、パラメーターがコレクションに格納される ParameterCollection 順序が重要になる場合があります。 たとえば、ODBC データ ソースとしてコントロールをSqlDataSource使用する場合、コレクション内ParameterCollectionのオブジェクトのParameter順序は、使用するパラメーター化された SQL クエリのパラメーターの順序と同じである必要があります。 ただし、Microsoft SQL Server でコントロールをSqlDataSource使用する場合、オブジェクトのParameter順序は重要ではありません。

重要

データ ソース コントロールを使用すると、値は検証なしでコマンド パラメーターに挿入されます。これは、セキュリティ上の脅威になる可能性があります。 コマンドを実行する前に、データ ソース コントロールのイベントを使用してパラメーター値を検証します。 詳細については、「スクリプトによる攻略の概要」を参照してください。

次の表に、さまざまなパラメーター クラスとその使用方法を示します。

Parameter クラス [説明]
Parameter 基本パラメーター クラス。 これを使用して、 プロパティを使用してローカル変数または任意の静的文字列に DefaultValue バインドします。
ControlParameter コントロールのプロパティまたはメソッドの戻り値にバインドするために使用できるパラメーター。
CookieParameter Cookie の値にバインドするために使用できるパラメーター。
FormParameter 現在のWeb Forms ページの属性にバインドするために使用できるパラメーター。
QueryStringParameter クエリ文字列のWeb Forms ページに渡される値にバインドするために使用できるパラメーター。
SessionParameter セッション変数の値にバインドするために使用できるパラメーター。
ProfileParameter ASP.NET Profile プロパティの値にバインドするために使用できるパラメーター。

コンストラクター

ParameterCollection()

継承クラス インスタンスによって使用されるクラスを初期化します。 このコンストラクターは、継承クラスによってのみ呼び出すことができます。

プロパティ

Count

StateManagedCollection コレクションに格納されている要素の数を取得します。

(継承元 StateManagedCollection)
Item[Int32]

コレクション内の指定したインデックスでの Parameter オブジェクトを取得または設定します。

Item[String]

コレクション内の指定した名前の Parameter オブジェクトを取得または設定します。

メソッド

Add(Parameter)

指定した Parameter オブジェクトをコレクションの末尾に追加します。

Add(String, DbType, String)

名前、データベース型、および既定値を指定して Parameter オブジェクトを作成し、コレクションの末尾に追加します。

Add(String, String)

名前と既定値を指定して Parameter オブジェクトを作成し、コレクションの末尾に追加します。

Add(String, TypeCode, String)

名前、Parameter、および既定値を指定して TypeCode オブジェクトを作成し、コレクションの末尾に追加します。

Clear()

StateManagedCollection コレクションからすべての項目を削除します。

(継承元 StateManagedCollection)
Contains(Parameter)

ParameterCollection コレクションに特定の値が格納されているかどうかを判断します。

CopyTo(Array, Int32)

特定の配列インデックスを開始位置として、配列に StateManagedCollection コレクションの要素をコピーします。

(継承元 StateManagedCollection)
CopyTo(Parameter[], Int32)

パラメーター配列の指定したインデックスをパラメーター コレクションにコピーします。

CreateKnownType(Int32)

既定の Parameter オブジェクトのインスタンスを作成します。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetEnumerator()

StateManagedCollection コレクションを反復処理する反復子を返します。

(継承元 StateManagedCollection)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetKnownTypes()

Parameter コレクションに格納できる ParameterCollection 型の配列を取得します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
GetValues(HttpContext, Control)

コレクションに現在格納されている Parameter オブジェクトの名前と対応する値の順序付けられたコレクションを取得します。

IndexOf(Parameter)

Parameter コレクション内の指定した ParameterCollection オブジェクトのインデックスを確認します。

Insert(Int32, Parameter)

Parameter コレクション内の指定したインデックス位置に、指定した ParameterCollection オブジェクトを挿入します。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
OnClear()

派生クラスでオーバーライドされた場合、Clear() メソッドによってコレクションからすべての項目が削除される前の補足作業を実行します。

(継承元 StateManagedCollection)
OnClearComplete()

コレクションの内容を消去した後に、追加のカスタム プロセスを実行します。

OnInsert(Int32, Object)

Insert(Int32, Parameter) メソッドが呼び出される前に発生します。

OnInsertComplete(Int32, Object)

Insert(Int32, Parameter) メソッドの完了後に発生します。

OnParametersChanged(EventArgs)

ParametersChanged イベントを発生させます。

OnRemove(Int32, Object)

派生クラスでオーバーライドされた場合、IList.Remove(Object) メソッドまたは IList.RemoveAt(Int32) メソッドによって、指定された項目がコレクションから削除される前の補足作業を実行します。

(継承元 StateManagedCollection)
OnRemoveComplete(Int32, Object)

Remove(Parameter) メソッドの完了後に発生します。

OnValidate(Object)

値を検証するときに、追加のカスタム プロセスを実行します。

Remove(Parameter)

指定した Parameter オブジェクトを ParameterCollection コレクションから削除します。

RemoveAt(Int32)

指定したインデックス位置にある Parameter オブジェクトを ParameterCollection コレクションから削除します。

SetDirty()

強制的に StateManagedCollection コレクション全体をビューステートにシリアル化します。

(継承元 StateManagedCollection)
SetDirtyObject(Object)

ビューステートから最後に読み込まれた後または保存された後に変更されたものとして、指定した Parameter オブジェクトをマークします。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)
UpdateValues(HttpContext, Control)

コレクションに格納された Parameter オブジェクトを反復処理し、各オブジェクトに対して Evaluate メソッドを呼び出します。

イベント

ParametersChanged

コレクションに格納された 1 つ以上の Parameter オブジェクトの状態が変更されたときに発生します。

明示的なインターフェイスの実装

ICollection.Count

StateManagedCollection コレクションに格納されている要素の数を取得します。

(継承元 StateManagedCollection)
ICollection.IsSynchronized

StateManagedCollection コレクションが同期されている (スレッド セーフである) かどうかを示す値を取得します。 このメソッドは、常に false を返します。

(継承元 StateManagedCollection)
ICollection.SyncRoot

StateManagedCollection コレクションへのアクセスを同期するために使用できるオブジェクトを取得します。 このメソッドは、常に null を返します。

(継承元 StateManagedCollection)
IEnumerable.GetEnumerator()

StateManagedCollection コレクションを反復処理する反復子を返します。

(継承元 StateManagedCollection)
IList.Add(Object)

項目を StateManagedCollection コレクションに追加します。

(継承元 StateManagedCollection)
IList.Clear()

StateManagedCollection コレクションからすべての項目を削除します。

(継承元 StateManagedCollection)
IList.Contains(Object)

StateManagedCollection コレクションに特定の値が格納されているかどうかを判断します。

(継承元 StateManagedCollection)
IList.IndexOf(Object)

StateManagedCollection コレクション内での指定した項目のインデックスを調べます。

(継承元 StateManagedCollection)
IList.Insert(Int32, Object)

StateManagedCollection コレクション内の指定したインデックスの位置に項目を挿入します。

(継承元 StateManagedCollection)
IList.IsFixedSize

StateManagedCollection コレクションが固定サイズかどうかを示す値を取得します。 このメソッドは、常に false を返します。

(継承元 StateManagedCollection)
IList.IsReadOnly

StateManagedCollection コレクションが読み取り専用かどうかを示す値を取得します。

(継承元 StateManagedCollection)
IList.Item[Int32]

指定されたインデックス位置の IStateManager 要素を取得します。

(継承元 StateManagedCollection)
IList.Remove(Object)

指定したオブジェクトのうち、StateManagedCollection コレクションで最初に出現したオブジェクトを削除します。

(継承元 StateManagedCollection)
IList.RemoveAt(Int32)

指定したインデックス位置にある IStateManager 要素を削除します。

(継承元 StateManagedCollection)
IStateManager.IsTrackingViewState

StateManagedCollection コレクションがビューステートへの変更を保存しているかどうかを示す値を取得します。

(継承元 StateManagedCollection)
IStateManager.LoadViewState(Object)

StateManagedCollection コレクションと、そのコレクションに格納されている IStateManager 項目の以前に保存されたビューステートを復元します。

(継承元 StateManagedCollection)
IStateManager.SaveViewState()

ページがサーバーにポストバックされた時間以降に発生した、StateManagedCollection コレクションとその各 IStateManager オブジェクトへの変更を保存します。

(継承元 StateManagedCollection)
IStateManager.TrackViewState()

StateManagedCollection コレクションとその各 IStateManager オブジェクトに自身のビューステートへの変更を追跡させ、同じページに対する要求間でこれらが永続化されるようにします。

(継承元 StateManagedCollection)

拡張メソッド

Cast<TResult>(IEnumerable)

IEnumerable の要素を、指定した型にキャストします。

OfType<TResult>(IEnumerable)

指定された型に基づいて IEnumerable の要素をフィルター処理します。

AsParallel(IEnumerable)

クエリの並列化を有効にします。

AsQueryable(IEnumerable)

IEnumerableIQueryable に変換します。

適用対象

こちらもご覧ください