SqlDataSourceView.Update(IDictionary, IDictionary, IDictionary) 메서드

정의

UpdateCommand SQL 문자열, UpdateParameters 컬렉션에 지정된 매개 변수, 지정된 keys, valuesoldValues 컬렉션의 값을 사용하여 업데이트 작업을 수행합니다.

public:
 int Update(System::Collections::IDictionary ^ keys, System::Collections::IDictionary ^ values, System::Collections::IDictionary ^ oldValues);
public int Update (System.Collections.IDictionary keys, System.Collections.IDictionary values, System.Collections.IDictionary oldValues);
override this.Update : System.Collections.IDictionary * System.Collections.IDictionary * System.Collections.IDictionary -> int
Public Function Update (keys As IDictionary, values As IDictionary, oldValues As IDictionary) As Integer

매개 변수

keys
IDictionary

업데이트 데이터베이스 작업을 수행하기 위해 IDictionary 속성과 함께 사용할 기본 키의 UpdateCommand입니다. 쿼리에 연결된 키가 없거나 UpdateCommand가 매개 변수가 있는 SQL 쿼리가 아닌 경우 null을 전달합니다.

values
IDictionary

업데이트 데이터베이스 작업을 수행하기 위해 IDictionary 속성과 함께 사용할 값의 UpdateCommand입니다. 쿼리에 연결된 매개 변수가 없거나 UpdateCommand가 매개 변수가 있는 SQL 쿼리가 아닌 경우 null을 전달합니다.

oldValues
IDictionary

데이터베이스의 원래 값을 나타내는 IDictionary입니다. 쿼리에 연결된 매개 변수가 없거나 UpdateCommand가 매개 변수가 있는 SQL 쿼리가 아닌 경우 null을 전달합니다.

반환

Int32

내부 데이터베이스에서 업데이트되는 행 수를 나타내는 값입니다.

예외

SqlDataSource가 내부 데이터 소스와 연결될 수 없는 경우

CanUpdate 속성은 false입니다.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다.를 SqlDataSource 데이터를 표시 하려면 컨트롤을 DropDownList 제어 및 업데이트 데이터 때를 제출 단추를 클릭 합니다. 합니다 UpdateCommand 매개 변수가 있는 SQL 문 및 두 개의 속성은 ControlParameter 매개 변수가 추가 됩니다는 UpdateParameters 컬렉션입니다. 경우는 제출 단추를 클릭 합니다 OnClick 호출 하려는 이벤트가 처리 됩니다는 Update 메서드 명시적으로.

<%@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 On_Click(Object source, EventArgs e) {
    try {
        SqlDataSource1.Update();
    }
    catch (Exception except) {
        // Handle the Exception.
    }

    Label2.Text="The record was updated successfully!";
 }
</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"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT EmployeeID, LastName, Address FROM Employees"
          UpdateCommand="UPDATE Employees SET Address=@Address WHERE EmployeeID=@EmployeeID">
          <UpdateParameters>
              <asp:ControlParameter Name="Address" ControlId="TextBox1" PropertyName="Text"/>
              <asp:ControlParameter Name="EmployeeID" ControlId="DropDownList1" PropertyName="SelectedValue"/>
          </UpdateParameters>
      </asp:SqlDataSource>

      <asp:DropDownList
          id="DropDownList1"
          runat="server"
          DataTextField="LastName"
          DataValueField="EmployeeID"
          DataSourceID="SqlDataSource1">
      </asp:DropDownList>

      <br />
      <asp:Label id="Label1" runat="server" Text="Enter a new address for the selected user."
        AssociatedControlID="TextBox1" />
      <asp:TextBox id="TextBox1" runat="server" />
      <asp:Button id="Submit" runat="server" Text="Submit" OnClick="On_Click" />

      <br /><asp:Label id="Label2" runat="server" Text="" />

    </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">

 Sub On_Click(ByVal source As Object, ByVal e As EventArgs)
    Try
        SqlDataSource1.Update()
    Catch except As Exception
        ' Handle the Exception.
    End Try

    Label2.Text="The record was updated successfully!"

 End Sub 'On_Click
</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"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT EmployeeID, LastName, Address FROM Employees"
          UpdateCommand="UPDATE Employees SET Address=@Address WHERE EmployeeID=@EmployeeID">
          <UpdateParameters>
              <asp:ControlParameter Name="Address" ControlId="TextBox1" PropertyName="Text"/>
              <asp:ControlParameter Name="EmployeeID" ControlId="DropDownList1" PropertyName="SelectedValue"/>
          </UpdateParameters>
      </asp:SqlDataSource>

      <asp:DropDownList
          id="DropDownList1"
          runat="server"
          DataTextField="LastName"
          DataValueField="EmployeeID"
          DataSourceID="SqlDataSource1">
      </asp:DropDownList>

      <br />
      <asp:Label id="Label1" runat="server" Text="Enter a new address for the selected user."
        AssociatedControlID="TextBox1" />
      <asp:TextBox id="TextBox1" runat="server" />
      <asp:Button id="Submit" runat="server" Text="Submit" OnClick="On_Click" />

      <br /><asp:Label id="Label2" runat="server" Text="" />
    </form>
  </body>
</html>

설명

Update 메서드 호출을 ExecuteUpdate 전달 하는 메서드는 keys, values, 및 oldValues 매개 변수. 자세한 내용은 SqlDataSource.UpdateCommand를 참조하세요.

적용 대상

추가 정보