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

정의

업데이트 작업을 수행합니다.

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);
member 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

업데이트할 레코드의 행 키 값입니다.

values
IDictionary

데이터 소스에서 업데이트할 행 값입니다.

oldValues
IDictionary

데이터 충돌을 감지하기 위해 계산하는 행 값입니다.

반환

Int32

업데이트 작업의 영향을 받는 레코드의 수입니다.

예제

다음 예제에서는 사용자가 단추를 클릭한 후 데이터 원본에서 레코드를 프로그래밍 방식으로 업데이트하는 방법을 보여 줍니다. 코드는 키 값이 포함된 개체, ListDictionary 원래 값을 포함하는 개체 및 ListDictionary 메서드에 새 값이 포함된 개체를 Update 전달 ListDictionary 합니다.

protected void Reset_Click(object sender, EventArgs e)
{
    ListDictionary keyValues = new ListDictionary();
    ListDictionary newValues = new ListDictionary();
    ListDictionary oldValues = new ListDictionary();

    keyValues.Add("ProductID", int.Parse(((Label)DetailsView1.FindControl("IDLabel")).Text));

    oldValues.Add("ProductName", ((Label)DetailsView1.FindControl("NameLabel")).Text);
    oldValues.Add("ProductCategory", ((Label)DetailsView1.FindControl("CategoryLabel")).Text);
    oldValues.Add("Color", ((Label)DetailsView1.FindControl("ColorLabel")).Text);

    newValues.Add("ProductName", "New Product");
    newValues.Add("ProductCategory", "General");
    newValues.Add("Color", "Not assigned");

    LinqDataSource1.Update(keyValues, newValues, oldValues);

    DetailsView1.DataBind();
}
Protected Sub Add_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim keyValues As New ListDictionary()
    Dim newValues As New ListDictionary()
    Dim oldValues As New ListDictionary()

    keyValues.Add("ProductID", Int32.Parse(CType(DetailsView1.FindControl("IDLabel"), Label).Text))

    oldValues.Add("ProductName", CType(DetailsView1.FindControl("NameLabel"), Label).Text)
    oldValues.Add("ProductCategory", CType(DetailsView1.FindControl("CategoryLabel"), Label).Text)
    oldValues.Add("Color", CType(DetailsView1.FindControl("ColorLabel"), Label).Text)

    newValues.Add("ProductName", "New Product")
    newValues.Add("ProductCategory", "General")
    newValues.Add("Color", "Not assigned")

    LinqDataSource1.Update(keyValues, newValues, oldValues)

    DetailsView1.DataBind()
End Sub

다음 예제에서는 이전 예제의 태그를 보여 줍니다.

<asp:LinqDataSource  
  ContextTypeName="ExampleDataContext" 
  TableName="Products" 
  EnableUpdate="true" 
  ID="LinqDataSource1" 
  runat="server">
</asp:LinqDataSource>
<asp:DetailsView 
  DataSourceID="LinqDataSource1" 
  AllowPaging="True" 
  ID="DetailsView1" 
  runat="server" 
  AutoGenerateRows="False">
  <Fields>
    <asp:templatefield HeaderText="Product ID">
        <itemtemplate>
            <asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ProductID") %>'></asp:Label>
        </itemtemplate>
    </asp:templatefield>
    <asp:templatefield HeaderText="Product Name">
        <itemtemplate>
            <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("ProductName") %>'></asp:Label>
        </itemtemplate>
    </asp:templatefield>
    <asp:templatefield HeaderText="Category">
        <itemtemplate>
            <asp:Label ID="CategoryLabel" runat="server" Text='<%# Bind("ProductCategory") %>'></asp:Label>
        </itemtemplate>
    </asp:templatefield>
    <asp:templatefield HeaderText="Color">
        <itemtemplate>
            <asp:Label ID="ColorLabel" runat="server" Text='<%# Bind("Color") %>'></asp:Label>
        </itemtemplate>
    </asp:templatefield>
  </Fields>
</asp:DetailsView>
<asp:button 
  ID="Button1"
  Text="Reset with default values" 
  runat="server" 
  onclick="Reset_Click" />
<asp:LinqDataSource  
  ContextTypeName="ExampleDataContext" 
  TableName="Products" 
  EnableUpdate="true" 
  ID="LinqDataSource1" 
  runat="server">
</asp:LinqDataSource>
<asp:DetailsView 
  DataSourceID="LinqDataSource1" 
  AllowPaging="True" 
  ID="DetailsView1" 
  runat="server" AutoGenerateRows="False">
  <Fields>
  <asp:templatefield HeaderText="Product ID">
        <itemtemplate>
            <asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ProductID") %>'></asp:Label>
        </itemtemplate>
    </asp:templatefield>
    <asp:templatefield HeaderText="Product Name">
        <itemtemplate>
            <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("ProductName") %>'></asp:Label>
        </itemtemplate>
    </asp:templatefield>
    <asp:templatefield HeaderText="Category">
        <itemtemplate>
            <asp:Label ID="CategoryLabel" runat="server" Text='<%# Bind("ProductCategory") %>'></asp:Label>
        </itemtemplate>
    </asp:templatefield>
    <asp:templatefield HeaderText="Color">
        <itemtemplate>
            <asp:Label ID="ColorLabel" runat="server" Text='<%# Bind("Color") %>'></asp:Label>
        </itemtemplate>
    </asp:templatefield>
  </Fields>
</asp:DetailsView>
<asp:button 
  ID="Button1"
  Text="Reset with default values" 
  runat="server" 
  onclick="Add_Click" />

설명

일반적으로 코드에서 메서드를 Update 호출할 필요가 없습니다. 데이터 바인딩된 컨트롤은 사용자가 레코드를 Update 업데이트하는 작업을 수행할 때 메서드를 자동으로 호출합니다. 데이터를 업데이트하기 위한 고유한 프로세스를 만들려는 경우 메서드를 명시적으로 호출 Update 합니다.

적용 대상