다음을 통해 공유


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

정의

SQL 문자열, 컬렉션에 UpdateCommandUpdateParameters 있는 매개 변수 및 지정된 keysvalues값 및 oldValues 컬렉션을 사용하여 업데이트 작업을 수행합니다.

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 사용할 기본 키입니다. 쿼리와 연결된 키가 없거나 매개 변수가 있는 SQL 쿼리가 아닌 경우 UpdateCommand 전달 null합니다.

values
IDictionary

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

oldValues
IDictionary

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

반환

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

예외

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 호출하고 , valuesoldValues 매개 변수를 keys전달합니다. 자세한 내용은 SqlDataSource.UpdateCommand를 참조하세요.

적용 대상

추가 정보