ObjectDataSourceView.InsertParameters プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ObjectDataSourceView.InsertParameters プロパティの意味・解説 

ObjectDataSourceView.InsertParameters プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

InsertMethod メソッドによって使用されるパラメータを格納するパラメータ コレクションを取得します。

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

Public ReadOnly Property
 InsertParameters As ParameterCollection
Dim instance As ObjectDataSourceView
Dim value As ParameterCollection

value = instance.InsertParameters
public ParameterCollection InsertParameters { get;
 }
public:
property ParameterCollection^ InsertParameters {
    ParameterCollection^ get ();
}
/** @property */
public ParameterCollection get_InsertParameters ()
public function get InsertParameters
 () : ParameterCollection

プロパティ値
InsertMethod プロパティによって使用されるパラメータを格納している ParameterCollection。

解説解説
使用例使用例

このセクションには、2 つのコード例が含まれています。ビジネス オブジェクトおよび DetailsView コントロールで、ObjectDataSource コントロールを使用してデータを挿入し、フィルタ処理済みのデータを表示する方法を最初のコード例に示します。最初のコード例で使用した Insert メソッドの実装例を 2 番目のコード例に示します。

ビジネス オブジェクトおよび DetailsView コントロールで、ObjectDataSource コントロールを使用してデータを挿入する方法を次のコード例に示します。DetailsView は、新しい NorthwindEmployee レコードと、自動的に生成された [挿入] ボタンを最初に表示します。DetailsView コントロールのフィールドにデータを入力した後、[挿入] ボタンをクリックします。InsertMethod プロパティは、Insert 操作を実行するメソッドを識別します。

[挿入] ボタンをクリックすると、InsertMethod プロパティで指定されたメソッド、および InsertParameters コレクションで指定されたパラメータを使用して Insert 操作が実行されます。このコード例では、スーパバイザの ID に対応する InsertParameters コレクション内のパラメータが 1 つ指定されています。その理由は、この ID が DetailsView コントロール用の Fields コレクション内に BoundField オブジェクトとして表示されていても、ObjectDataSource コントロールには文字列として渡されるためです。Int32 値に設定した Type プロパティを指定して、この ID を明示的に InsertParameters コレクションに追加すると、この ID は string ではなく、int として、ObjectDataSource によってメソッドに正しく渡されます。

Insert 操作を実行すると、InsertMethod プロパティで識別されたメソッドが呼び出されます。オブジェクトの Insert メソッドがパラメータを含むメソッド シグネチャを持っている場合、Insert を正常に完了するためには、InsertParameters コレクションにメソッド シグネチャ パラメータと一致する名前のパラメータがある必要があります。

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB"
 Assembly="Samples.AspNet.VB"
 %>
<%@ Import namespace="Samples.AspNet.VB"
 %>
<%@ Page language="vb" %>
<html>
  <head>
    <title>ObjectDataSource - VB Example</title>
  </head>
  <body>
    <form id="Form1" method="post"
 runat="server">

        <asp:detailsview
          id="DetailsView1"
          runat="server"
          autogenerateinsertbutton="True"
          autogeneraterows="false"
          datasourceid="ObjectDataSource1" >
          <fields>
            <asp:BoundField headertext="FirstName"
 datafield="FirstName" />
            <asp:BoundField headertext="LastName"
   datafield="LastName" />
            <asp:BoundField headertext="Title"
      datafield="Title" />
            <asp:BoundField headertext="Courtesy"
   datafield="Courtesy" />
            <asp:BoundField headertext="Supervisor"
 datafield="Supervisor" />
          </fields>
        </asp:detailsview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          insertmethod="InsertNewEmployeeWrapper"
          typename="Samples.AspNet.VB.EmployeeLogic"
 >
          <selectparameters>
            <asp:parameter name="anID" defaultvalue="-1"
 />
          </selectparameters>
          <insertparameters>
            <asp:parameter name="Supervisor" type="Int32"
 />
          </insertparameters>
        </asp:objectdatasource>

    </form>
  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS"
 Assembly="Samples.AspNet.CS" %>
<%@ Import namespace="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<html>
  <head>
    <title>ObjectDataSource - C# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <asp:detailsview
          id="DetailsView1"
          runat="server"
          autogenerateinsertbutton="True"
          autogeneraterows="false"
          datasourceid="ObjectDataSource1" >
          <fields>
            <asp:BoundField headertext="FirstName" datafield="FirstName"
 />
            <asp:BoundField headertext="LastName"   datafield="LastName"
 />
            <asp:BoundField headertext="Title"      datafield="Title"
 />
            <asp:BoundField headertext="Courtesy"   datafield="Courtesy"
 />
            <asp:BoundField headertext="Supervisor" datafield="Supervisor"
 />
          </fields>
        </asp:detailsview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          insertmethod="InsertNewEmployeeWrapper"
          typename="Samples.AspNet.CS.EmployeeLogic" >
          <selectparameters>
            <asp:parameter name="anID" defaultvalue="-1" />
          </selectparameters>
          <insertparameters>
            <asp:parameter name="Supervisor" type="Int32"
 />
          </insertparameters>
        </asp:objectdatasource>

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

前のコード例で使用した Insert メソッドの実装例を次のコード例に示します。InsertNewEmployeeWrapper メソッドが EmployeeLogic 中間層オブジェクトに追加されているため、実際のビジネス ロジックをあまりリライトせずに、オブジェクトが Web シナリオで ObjectDataSource コントロールを簡単に使用できるようになります。

' This InsertNewEmployeeWrapper method is a wrapper method that enables
' the use of ObjectDataSource and InsertParameters, without
' substantially rewriting the true implementation for the NorthwindEmployee
' or the EmployeeLogic objects.
'
' The parameters to the method must be named the same as the
' DataControlFields used by the GridView or DetailsView controls.
Public Shared Sub InsertNewEmployeeWrapper(FirstName
 As String, LastName As
 String, Title As String, Courtesy As String, Supervisor As Integer)
   ' Build the NorthwindEmployee object and
   ' call the true  implementation.
   Dim tempEmployee As New
 NorthwindEmployee()

   tempEmployee.FirstName = FirstName
   tempEmployee.LastName = LastName
   tempEmployee.Title = Title
   tempEmployee.Courtesy = Courtesy
   tempEmployee.Supervisor = Supervisor

   ' Call the true implementation.
   InsertNewEmployee(tempEmployee)
End Sub 'InsertNewEmployeeWrapper


Public Shared Sub InsertNewEmployee(ne
 As NorthwindEmployee)
   Dim retval As Boolean
 = ne.Save()
   If Not retval Then
      Throw New NorthwindDataException("InsertNewEmployee
 failed.")
   End If
End Sub 'InsertNewEmployee
// This InsertNewEmployeeWrapper method is a wrapper method that enables
// the use of ObjectDataSource and InsertParameters, without
// substantially rewriting the true implementation for the NorthwindEmployee
// or the EmployeeLogic objects.
//
// The parameters to the method must be named the same as the
// DataControlFields used by the GridView or DetailsView controls.
public static void InsertNewEmployeeWrapper
 (string FirstName,
                                             string LastName,
                                             string Title,
                                             string Courtesy,
                                             int    Supervisor)
{
  // Build the NorthwindEmployee object and
  // call the true  implementation.
  NorthwindEmployee tempEmployee = new NorthwindEmployee();

  tempEmployee.FirstName  = FirstName;
  tempEmployee.LastName   = LastName;
  tempEmployee.Title      = Title;
  tempEmployee.Courtesy   = Courtesy;
  tempEmployee.Supervisor = Supervisor;

  // Call the true implementation.
  InsertNewEmployee(tempEmployee);
}

public static void InsertNewEmployee(NorthwindEmployee
 ne) {
  bool retval = ne.Save();
  if (! retval) { throw new NorthwindDataException("InsertNewEmployee
 failed."); }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ObjectDataSourceView クラス
ObjectDataSourceView メンバ
System.Web.UI.WebControls 名前空間
ObjectDataSourceView.InsertMethod プロパティ
Insert



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

ObjectDataSourceView.InsertParameters プロパティのお隣キーワード
検索ランキング

   

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



ObjectDataSourceView.InsertParameters プロパティのページの著作権

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

©2026 GRAS Group, Inc.RSS