LinqDataSource.Update(IDictionary, IDictionary, IDictionary) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Voert een updatebewerking uit.
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
Parameters
- keys
- IDictionary
De rijsleutelwaarden voor de records die moeten worden bijgewerkt.
- values
- IDictionary
De rijwaarden die moeten worden bijgewerkt in de gegevensbron.
- oldValues
- IDictionary
De rijwaarden die worden geëvalueerd om gegevensconflicten te detecteren.
Retouren
Het aantal records dat wordt beïnvloed door de updatebewerking.
Voorbeelden
In het volgende voorbeeld ziet u hoe u programmatisch een record in de gegevensbron bijwerkt nadat de gebruiker op een knop heeft geklikt. De code geeft een ListDictionary object door dat de sleutelwaarde bevat, een ListDictionary object dat de oorspronkelijke waarden bevat en een ListDictionary object dat de nieuwe waarden bevat aan de Update methode.
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
In het volgende voorbeeld ziet u de markeringen voor het vorige voorbeeld.
<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" />
Opmerkingen
Normaal gesproken hoeft u de Update methode niet aan te roepen vanuit uw code. Het gegevensgebonden besturingselement roept automatisch de Update methode aan wanneer de gebruiker actie onderneemt om een record bij te werken. U roept de Update methode expliciet aan wanneer u uw eigen proces wilt maken voor het bijwerken van gegevens.