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

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

ObjectDataSource.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 ObjectDataSource
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。

解説解説

InsertParameters コレクション格納されているパラメータInsertMethod プロパティ シグネチャパラメータは、名前と型が一致している必要がありますパラメータ名では、大文字と小文字区別されます。GridView コントロールや DetailsView コントロールなど、パラメータ提供するデータ バインド コントロール使用する場合、ObjectDataSource コントロールは、コレクション明示的に指定されすべてのパラメータデータ バインド コントロールによって提供されるパラメータ自動的にマージます。このことは、データ バインド コントロールパラメータを常に String 型として提供しメソッド シグネチャ数値型日付型含まれる場合は、InsertParameters コレクション適切な型で明示的にパラメータ追加する必要があるという点で重要です。それ以外場合ObjectDataSource コントロールは、コレクション内のパラメータ定義された型に基づいてパラメータキャストます。詳細については、「ObjectDataSource コントロールにおけるパラメータ使用」を参照してください

InsertParameters プロパティは、ObjectDataSource コントロール関連付けられた ObjectDataSourceView が格納する InsertParameters プロパティ取得します

パラメータマージオブジェクト有効期間、およびメソッド解決詳細については、InsertMethodトピック参照してください

使用例使用例

このセクションには、2 つコード例含まれています。1 つ目のコード例では、ビジネス オブジェクトおよび DetailsView コントロールで、ObjectDataSource オブジェクト使用してデータ挿入する方法示します2 つ目のコード例では、1 つ目のコード例使用されている Insert メソッド実装の例示します

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

[挿入] ボタンクリックすると、InsertMethod プロパティ指定されメソッド、および InsertParameters コレクション指定され任意のパラメータ使用して操作実行されます。このコード例では、管理者ID対応するパラメータInsertParameters コレクション指定されています。これは、IDDetailsView コントロールRows コレクションに BoundField オブジェクトとして表示される場合でも、ID は文字列として ObjectDataSource コントロール渡されるためです。Type プロパティを Int32 値に設定して、これを InsertParameters コレクション明示的に追加することで、ObjectDataSource によって文字列ではなく Int32 として正しくメソッド渡されます。

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."); }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ObjectDataSource クラス
ObjectDataSource メンバ
System.Web.UI.WebControls 名前空間
ObjectDataSource.InsertMethod プロパティ
Insert


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

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

辞書ショートカット

すべての辞書の索引

「ObjectDataSource.InsertParameters プロパティ」の関連用語

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

   

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



ObjectDataSource.InsertParameters プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS