다음을 통해 공유


ObjectDataSource.InsertParameters 속성

정의

속성에서 사용하는 InsertMethod 매개 변수를 포함하는 매개 변수 컬렉션을 가져옵니다.

public:
 property System::Web::UI::WebControls::ParameterCollection ^ InsertParameters { System::Web::UI::WebControls::ParameterCollection ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.ParameterCollection InsertParameters { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.InsertParameters : System.Web.UI.WebControls.ParameterCollection
Public ReadOnly Property InsertParameters As ParameterCollection

속성 값

ParameterCollection 속성으로 식별되는 메서드에서 사용하는 매개 변수를 InsertMethod 포함하는 A입니다.

특성

예제

이 섹션에는 두 가지 코드 예제가 포함되어 있습니다. 첫 번째 코드 예제에서는 비즈니스 개체와 DetailsView 컨트롤을 사용하여 ObjectDataSource 데이터를 삽입하는 방법을 보여 줍니다. 두 번째 코드 예제에서는 첫 번째 코드 예제에서 사용 되는 메서드의 Insert 예제 구현을 제공 합니다.

다음 코드 예제에서는 비즈니스 개체와 컨트롤을 사용 하 여 데이터를 삽입 하는 컨트롤을 DetailsView 사용 ObjectDataSource 하는 방법을 보여 줍니다. 처음에는 DetailsView 자동으로 생성된 삽입 단추와 함께 새 NorthwindEmployee 레코드에 대한 데이터를 입력할 수 있는 텍스트 상자가 표시됩니다. 컨트롤의 DetailsView 필드에 데이터를 입력한 후 삽입 단추를 클릭합니다. 이 속성은 InsertMethod 삽입 작업을 수행하는 메서드를 식별합니다.

삽입 단추를 클릭하면 속성에 지정된 메서드와 컬렉션에 InsertMethod 지정된 InsertParameters 매개 변수를 사용하여 작업이 수행됩니다. 이 코드 예제에서는 감독자의 ID에 InsertParameters 해당하는 하나의 매개 변수가 컬렉션에 지정됩니다. 이는 ID가 컨트롤의 컬렉션 DetailsViewRows 개체로 BoundField 표시되더라도 컨트롤에 문자열로 전달되기 때문 ObjectDataSource 입니다. 속성이 값으로 InsertParametersType 설정된 Int32 컬렉션에 명시적으로 추가하면 메서드가 문자열이 아닌 메서드Int32에 의해 ObjectDataSource 올바르게 전달됩니다.

Insert 작업이 수행되면 속성으로 식별되는 메서드가 InsertMethod 호출됩니다. 개체의 메서드에 Insert 매개 변수 InsertParameters 가 포함된 메서드 시그니처가 있는 경우 성공적으로 완료하려면 컬렉션에 메서드 시그니처 매개 변수와 일치하는 이름이 있는 매개 변수가 Insert 포함되어야 합니다.

중요합니다

클라이언트에서 받은 매개 변수 값의 유효성을 검사해야 합니다. 런타임은 매개 변수 값을 속성으로 대체합니다 InsertMethod .

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ Import namespace="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <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"
          defaultmode="Insert" >
          <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>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<%@ Import namespace="Samples.AspNet.VB" %>
<%@ Page language="vb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <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"
          defaultmode="Insert" >
          <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>

다음 코드 예제에서는 앞의 코드 예제에서 사용 하는 메서드의 Insert 예제 구현을 제공 합니다. 이 InsertNewEmployeeWrapper 메서드는 클래스 개요에 제공된 중간 계층 개체에 ObjectDataSource 추가 EmployeeLogic 되어 실제 비즈니스 논리를 크게 다시 작성하지 않고도 개체가 웹 시나리오에서 컨트롤을 더 쉽게 ObjectDataSource 사용할 수 있도록 합니다.

예제를 실행하려면 클래스 개요에 NorthwindEmployee 제공되는 클래스가 ObjectDataSource 있어야 합니다. 이 예제에서는 매개 변수를 사용하여 새 데이터베이스 레코드에 대한 데이터를 가져오는 비즈니스 개체 메서드에 연결하는 ObjectDataSource 방법만 보여 줍니다. 클래스의 NorthwindEmployee 메서드에 데이터베이스 Save 를 업데이트하는 코드가 포함되어 있지 않으므로 이 예제에서는 데이터베이스에 레코드를 추가하지 않습니다.

// 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."); }
}
' 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


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

설명

컬렉션에 포함된 매개 변수의 이름과 형식은 속성 서명에 InsertParameters 있는 매개 변수 InsertMethod 의 이름 및 형식과 일치해야 합니다. 매개 변수 이름은 대/소문자를 구분합니다. 컨트롤과 DetailsViewObjectDataSource 같은 GridView 매개 변수를 제공하는 데이터 바인딩된 컨트롤을 사용하는 경우 컨트롤은 컬렉션에 명시적으로 지정된 모든 매개 변수를 데이터 바인딩된 컨트롤에서 제공하는 매개 변수와 자동으로 병합합니다. 데이터 바인딩된 컨트롤은 항상 해당 매개 변수를 형식으로 String 제공하고 메서드 서명에 숫자 또는 날짜 형식이 포함된 경우 올바른 형식의 매개 변수를 컬렉션에 InsertParameters 명시적으로 포함해야 하기 때문에 중요합니다. 그렇지 않으면 컨트롤이 컬렉션의 ObjectDataSource 매개 변수로 정의된 형식에 따라 매개 변수를 캐스팅하려고 시도합니다. 자세한 내용은 ObjectDataSource 컨트롤에서 매개 변수 사용을 참조하세요.

이 속성은 InsertParameters 컨트롤과 연결된 속성에 ObjectDataSourceView 포함된 속성을 검색 InsertParameters 합니다ObjectDataSource.

매개 변수 병합, 개체 수명 및 메서드 확인에 대한 자세한 내용은 다음을 참조하세요 InsertMethod.

적용 대상

추가 정보