SqlDataSource.UpdateCommand 속성

정의

SqlDataSource 컨트롤에서 내부 데이터베이스의 데이터를 업데이트하는 데 사용하는 SQL 문자열을 가져오거나 설정합니다.

public:
 property System::String ^ UpdateCommand { System::String ^ get(); void set(System::String ^ value); };
public string UpdateCommand { get; set; }
member this.UpdateCommand : string with get, set
Public Property UpdateCommand As String

속성 값

SqlDataSource에서 데이터를 업데이트하는 데 사용하는 SQL 문자열입니다.

예제

이 섹션에는 두 코드 예제가 있습니다. 첫 번째 코드 예제에는 설정 하는 방법을 보여 줍니다.는 UpdateCommand 의 속성을 SqlDataSource 사용 하 여 Microsoft SQL Server 데이터베이스에서 데이터를 제어 및 업데이트는 GridView 컨트롤. 두 번째 코드 예제에서는 사용 하 여 ODBC 데이터베이스의 데이터를 업데이트 하는 방법에 설명 합니다 GridView 제어 합니다.

다음 코드 예제에는 설정 하는 방법을 보여 줍니다.는 UpdateCommand 의 속성을 SqlDataSource 사용 하 여 SQL Server 데이터베이스에서 데이터를 제어 및 업데이트를 GridView 컨트롤입니다. GridView 자동으로 채웁니다를 UpdateParameters 컬렉션, 매개 변수를 유추 합니다 BoundField 개체 및 호출를 Update 메서드 때를 업데이트 링크를 편집할 수 있는 GridView을 선택 합니다. 이 예제에서는 일부 사후 처리에도 포함 되어 있습니다: 레코드 업데이트 되 면 알림 전자 메일 메시지를 전송 됩니다.

<%@Page  Language="C#" %>
<%@Import Namespace="System.Web.Mail" %>
<!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 OnDSUpdatedHandler(Object source, SqlDataSourceStatusEventArgs e) {
    if (e.AffectedRows > 0) {
        // Perform any additional processing, 
        // such as setting a status label after the operation.
        Label1.Text = Request.LogonUserIdentity.Name +
            " changed user information successfully!";    
    }
    else {
        Label1.Text = "No data updated!";
    }
 }
</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:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataSet"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
          UpdateCommand="Update Employees SET FirstName=@FirstName,LastName=@LastName,Title=@Title WHERE EmployeeID=@EmployeeID"
          OnUpdated="OnDSUpdatedHandler">
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AutoGenerateColumns="False"
          DataKeyNames="EmployeeID"
          AutoGenerateEditButton="True"
          DataSourceID="SqlDataSource1">
          <columns>
              <asp:BoundField HeaderText="First Name" DataField="FirstName" />
              <asp:BoundField HeaderText="Last Name" DataField="LastName" />
              <asp:BoundField HeaderText="Title" DataField="Title" />
          </columns>
      </asp:GridView>

      <asp:Label
          id="Label1"
          runat="server">
      </asp:Label>

    </form>
  </body>
</html>
<%@Page  Language="VB" %>
<%@Import Namespace="System.Web.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

 Sub OnDSUpdatedHandler(ByVal source As Object, ByVal e As SqlDataSourceStatusEventArgs)
    If e.AffectedRows > 0 Then
        ' Perform any additional processing, 
        ' such as setting a status label after the operation.        
        Label1.Text = Request.LogonUserIdentity.Name & _
            " changed user information successfully!"
    Else 
        Label1.Text = "No data updated!"
    End If
 End Sub 'OnDSUpdatedHandler
</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:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataSet"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
          UpdateCommand="Update Employees SET FirstName=@FirstName,LastName=@LastName,Title=@Title WHERE EmployeeID=@EmployeeID"
          OnUpdated="OnDSUpdatedHandler">
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AutoGenerateColumns="False"
          DataKeyNames="EmployeeID"
          AutoGenerateEditButton="True"
          DataSourceID="SqlDataSource1">
          <columns>
              <asp:BoundField HeaderText="First Name" DataField="FirstName" />
              <asp:BoundField HeaderText="Last Name" DataField="LastName" />
              <asp:BoundField HeaderText="Title" DataField="Title" />
          </columns>
      </asp:GridView>

      <asp:Label
          id="Label1"
          runat="server">
      </asp:Label>

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

앞의 코드 예제와 기능적으로 동일 인 다음 코드 예제를 사용 하 여 ODBC 데이터베이스의 데이터를 업데이트 하는 방법에 설명 합니다 GridView 제어 합니다. ProviderName ODBC 용 ADO.NET 공급자를로 System.Data.Odbc, 및 ConnectionString 속성은 ODBC 데이터 원본 이름 (DSN)의 이름으로 설정 합니다.

<%@Page  Language="C#" %>
<%@Import Namespace="System.Web.Mail" %>
<!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 OnDSUpdatedHandler(Object source, SqlDataSourceStatusEventArgs e) {
    if (e.AffectedRows > 0) {
        // Perform any additional processing, such as sending an email notification.
        Label1.Text = Request.LogonUserIdentity.Name +
            " changed user information successfully!";
    }
    else {
        Label1.Text = "No data updated!";
    }
 }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <!-- This example uses a Northwind database that is hosted by an ODBC-compliant
         database. To run this sample, create an ODBC DSN to any database that hosts
         the Northwind database, including Microsoft SQL Server or Microsoft Access,
         change the name of the DSN in the ConnectionString, and view the page.
    -->
    <form id="form1" runat="server">

      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          ProviderName="System.Data.Odbc"
          DataSourceMode="DataSet"
          ConnectionString="dsn=myodbc3dsn;"
          SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
          UpdateCommand="Update Employees SET FirstName=?,LastName=?,Title=? WHERE EmployeeID=?"
          OnUpdated="OnDSUpdatedHandler">
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AutoGenerateColumns="False"
          DataKeyNames="EmployeeID"
          AutoGenerateEditButton="True"
          DataSourceID="SqlDataSource1">
          <columns>
              <asp:BoundField HeaderText="First Name" DataField="FirstName" />
              <asp:BoundField HeaderText="Last Name" DataField="LastName" />
              <asp:BoundField HeaderText="Title" DataField="Title" />
          </columns>
      </asp:GridView>

      <asp:Label
          id="Label1"
          runat="server">
      </asp:Label>

    </form>
  </body>
</html>
<%@Page  Language="VB" %>
<%@Import Namespace="System.Web.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

 Sub OnDSUpdatedHandler(ByVal source As Object, ByVal e As SqlDataSourceStatusEventArgs)
    If e.AffectedRows > 0 Then
        ' Perform any additional processing, such as setting a status label.
        Label1.Text = Request.LogonUserIdentity.Name & _
            " changed user information successfully!"
    Else
        Label1.Text = "No data updated!"
    End If
 End Sub 'OnDSUpdatedHandler

</script>


<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <!-- This example uses a Northwind database that is hosted by an ODBC-compliant
         database. To run this sample, create an ODBC DSN to any database that hosts
         the Northwind database, including Microsoft SQL Server or Microsoft Access,
         change the name of the DSN in the ConnectionString, and view the page.
    -->
    <form id="form1" runat="server">

      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          ProviderName="System.Data.Odbc"
          DataSourceMode="DataSet"
          ConnectionString="dsn=myodbc3dsn;"
          SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
          UpdateCommand="Update Employees SET FirstName=?,LastName=?,Title=? WHERE EmployeeID=?"
          OnUpdated="OnDSUpdatedHandler">
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AutoGenerateColumns="False"
          DataKeyNames="EmployeeID"
          AutoGenerateEditButton="True"
          DataSourceID="SqlDataSource1">
          <columns>
              <asp:BoundField HeaderText="First Name" DataField="FirstName" />
              <asp:BoundField HeaderText="Last Name" DataField="LastName" />
              <asp:BoundField HeaderText="Title" DataField="Title" />
          </columns>
      </asp:GridView>

      <asp:Label
          id="Label1"
          runat="server">
      </asp:Label>

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

설명

합니다 UpdateCommand SQL 쿼리 또는 저장된 프로시저의 이름을 나타내며에서 사용 되는 Update 메서드.

데이터베이스 제품마다 다양한 SQL을 사용하기 때문에 SQL 문자열의 구문은 현재 사용 중인 ADO.NET 공급자(ProviderName 속성으로 식별 가능)에 따라 달라집니다. SQL 문자열이 매개 변수가 있는 쿼리나 명령인 경우 매개 변수의 자리 표시자도 사용 중인 ADO.NET 공급자에 따라 달라집니다. 예를 들어 공급자가 합니다 System.Data.SqlClient에 대 한 기본 공급자 인를 SqlDataSource 클래스는 매개 변수의 자리 표시자는 '@parameterName'. 그러나 공급자로 설정 된 경우는 System.Data.Odbc 또는 System.Data.OleDb, 매개 변수의 자리 표시자는 '?'합니다. 매개 변수가 있는 SQL 쿼리 및 명령에 대 한 자세한 내용은 참조 하세요. SqlDataSource 컨트롤을 사용 하 여 매개 변수를 사용 하 여입니다.

UpdateCommand 속성 수는 SQL 문자열이 나 저장된 프로시저의 이름을 데이터 원본에서 저장된 프로시저를 지 원하는 경우.

UpdateCommand 에 위임 하는 속성을 UpdateCommand 의 속성을 SqlDataSourceView 개체와 연결 된는 SqlDataSource 컨트롤.

중요

보안상의 이유로 UpdateCommand 속성 저장 되지 않습니다 보기 상태입니다. 클라이언트에서 보기 상태의 내용이 디코딩할 수 이기 때문에 데이터베이스 구조에 대 한 중요 한 정보를 보기 저장 상태 발생할 수 정보 공개 취약성이 있습니다.

중요

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

적용 대상

추가 정보