LinqDataSource.Update(IDictionary, IDictionary, IDictionary) Yöntem

Tanım

Güncelleştirme işlemi gerçekleştirir.

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

Parametreler

keys
IDictionary

Güncelleştirilecek kayıtların satır anahtarı değerleri.

values
IDictionary

Veri kaynağında güncelleştirilecek satır değerleri.

oldValues
IDictionary

Veri çakışmalarını algılamak için değerlendirilen satır değerleri.

Döndürülenler

Güncelleştirme işleminden etkilenen kayıtların sayısı.

Örnekler

Aşağıdaki örnekte, kullanıcı bir düğmeye tıkladıktan sonra veri kaynağındaki bir kaydı program aracılığıyla güncelleştirme gösterilmektedir. Kod anahtar değerini içeren bir ListDictionary nesneyi, özgün değerleri içeren bir ListDictionary nesneyi ve yeni değerleri içeren bir ListDictionary nesneyi yöntemine Update geçirir.

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

Aşağıdaki örnekte, önceki örneğin işaretlemesi gösterilmektedir.

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

Açıklamalar

Genellikle, kodunuzdan yöntemini çağırmanız Update gerekmez. Veriye bağlı denetim, kullanıcı bir kaydı güncelleştirmek için eyleme geçtiğinde yöntemini otomatik olarak çağırır Update . Verileri güncelleştirmek için kendi işleminizi oluşturmak istediğinizde yöntemini açıkça çağırırsınız Update .

Şunlara uygulanır