SqlDataSource.InsertParameters 속성

정의

InsertCommand 속성에서 사용하는 매개 변수가 들어 있는 매개 변수 컬렉션을 SqlDataSourceView 컨트롤에 연결된 SqlDataSource 개체에서 가져옵니다.

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 속성에서 사용하는 매개 변수가 포함된 InsertCommand입니다.

특성

예제

다음 코드 예제에서는 사용 하 여 데이터베이스에 데이터를 삽입 하는 방법에 설명 합니다 SqlDataSource 제어 및 간단한 Web Forms 페이지입니다. 데이터 테이블의 현재 데이터에 표시 됩니다는 DropDownList 제어 합니다. 값을 입력 하 여 새 레코드를 추가할 수 있습니다는 TextBox 컨트롤 및 클릭 합니다 삽입 단추입니다. 경우는 삽입 단추를 클릭 하면, 지정된 된 값은 데이터베이스에 삽입 및 DropDownList 컨트롤 새로 고쳐집니다.

중요

잠재적인 보안 위협을 이기도 유효성 검사 없이 매개 변수 값을 삽입할 및이 예제에는 잠재적인 보안 위협을 사용자 입력을 허용 하는 텍스트 상자가 포함 됩니다. 사용 된 Inserting 이벤트 쿼리를 실행 하기 전에 매개 변수 값의 유효성 검사를 합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

참고

이 예제에서는 데이터 액세스에 대 한 선언적 구문을 사용 하는 방법을 보여 줍니다. 태그 대신 코드를 사용 하 여 데이터에 액세스 하는 방법에 대 한 자세한 내용은 Visual Studio에서 데이터 액세스합니다.

<%@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">
private void InsertShipper (object source, EventArgs e) {
  SqlDataSource1.Insert();
}
</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:dropdownlist
        id="DropDownList1"
        runat="server"
        datasourceid="SqlDataSource1"
        datatextfield="CompanyName"
        datavaluefield="ShipperID" />

<!-- Security Note: The SqlDataSource uses a FormParameter,
     Security Note: which does not perform validation of input from the client.
     Security Note: To validate the value of the FormParameter, handle the Inserting event. -->

      <asp:sqldatasource
        id="SqlDataSource1"
        runat="server"
        connectionstring="<%$ ConnectionStrings:MyNorthwind %>"
        selectcommand="SELECT CompanyName,ShipperID FROM Shippers"
        insertcommand="INSERT INTO Shippers (CompanyName,Phone) VALUES (@CoName,@Phone)">
          <insertparameters>
            <asp:formparameter name="CoName" formfield="CompanyNameBox" />
            <asp:formparameter name="Phone"  formfield="PhoneBox" />
          </insertparameters>
      </asp:sqldatasource>

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

      <asp:RequiredFieldValidator
        id="RequiredFieldValidator1"
        runat="server"
        ControlToValidate="CompanyNameBox"
        Display="Static"
        ErrorMessage="Please enter a company name." />

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

      <asp:RequiredFieldValidator
        id="RequiredFieldValidator2"
        runat="server"
        ControlToValidate="PhoneBox"
        Display="Static"
        ErrorMessage="Please enter a phone number." />

      <br /><asp:button
           id="Button1"
           runat="server"
           text="Insert New Shipper"
           onclick="InsertShipper" />

    </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 InsertShipper (ByVal Source As Object, ByVal e As EventArgs)
  SqlDataSource1.Insert()
End Sub ' InsertShipper
</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:dropdownlist
        id="DropDownList1"
        runat="server"
        datasourceid="SqlDataSource1"
        datatextfield="CompanyName"
        datavaluefield="ShipperID" />

<!-- Security Note: The SqlDataSource uses a FormParameter,
     Security Note: which does not perform validation of input from the client.
     Security Note: To validate the value of the FormParameter, handle the Inserting event. -->

      <asp:sqldatasource
        id="SqlDataSource1"
        runat="server"
        connectionstring="<%$ ConnectionStrings:MyNorthwind %>"
        selectcommand="SELECT CompanyName,ShipperID FROM Shippers"
        insertcommand="INSERT INTO Shippers (CompanyName,Phone) VALUES (@CoName,@Phone)">
          <insertparameters>
            <asp:formparameter name="CoName" formfield="CompanyNameBox" />
            <asp:formparameter name="Phone"  formfield="PhoneBox" />
          </insertparameters>
      </asp:sqldatasource>

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

      <asp:RequiredFieldValidator
        id="RequiredFieldValidator1"
        runat="server"
        ControlToValidate="CompanyNameBox"
        Display="Static"
        ErrorMessage="Please enter a company name." />

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

      <asp:RequiredFieldValidator
        id="RequiredFieldValidator2"
        runat="server"
        ControlToValidate="PhoneBox"
        Display="Static"
        ErrorMessage="Please enter a phone number." />

      <br /><asp:button
           id="Button1"
           runat="server"
           text="Insert New Shipper"
           onclick="InsertShipper" />

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

설명

InsertParameters 속성 검색을 InsertParameters 속성에 포함 된를 SqlDataSourceView 연관 된 개체는 SqlDataSource 컨트롤.

경우는 InsertCommand 속성 매개 변수가 있는 SQL 쿼리를 포함 합니다 InsertParameters 컬렉션에 포함 된 Parameter SQL 문자열에 매개 변수 자리 표시자에 해당 하는 개체입니다.

ADO.NET 공급자에서 매개 변수의 순서에 따라는 InsertParameters 컬렉션 중요할 수 있습니다. 합니다 System.Data.OleDbSystem.Data.Odbc 공급자 매개 변수가 있는 SQL 쿼리가 매개 변수가 나타나는 순서에 따라 컬렉션의 매개 변수를 연결 합니다. System.Data.SqlClient 은 기본 ADO.NET 공급자는 공급자에 대 한는 SqlDataSource 제어, SQL 쿼리의 자리 표시자 별칭을 가진 매개 변수의 이름과 일치 하는 방법으로 컬렉션의 매개 변수를 연결 합니다. 매개 변수가 있는 SQL 쿼리 및 명령에 대 한 자세한 내용은 참조 하세요. SqlDataSource 컨트롤을 사용 하 여 매개 변수를 사용 하 여입니다.

중요

값 매개 변수 유효성 검사는 잠재적인 보안 위협을 없이 삽입 됩니다. 사용 된 Filtering 이벤트 쿼리를 실행 하기 전에 매개 변수 값의 유효성 검사를 합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

적용 대상

추가 정보