ObjectDataSourceView.InsertParameters プロパティ
アセンブリ: System.Web (system.web.dll 内)

Dim instance As ObjectDataSourceView Dim value As ParameterCollection value = instance.InsertParameters
InsertMethod プロパティによって使用されるパラメータを格納している ParameterCollection。

InsertParameters コレクションに格納されているパラメータと InsertMethod プロパティ シグネチャで指定されたメソッド内のパラメータは、名前と型が一致している必要があります。GridView や DetailsView などのパラメータを提供するデータ バインド コントロールを使用する場合、ObjectDataSource コントロールは、コレクションで明示的に指定されたすべてのパラメータと、データ バインド コントロールによって提供されるパラメータとを自動的にマージします。詳細については、「InsertMethod」を参照してください。

このセクションには、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."); } }

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- ObjectDataSourceView.InsertParameters プロパティのページへのリンク