This documentation is archived and is not being maintained.

LinqDataSource.Update Method

Performs an update operation.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

Public Function Update ( _
	keys As IDictionary, _
	values As IDictionary, _
	oldValues As IDictionary _
) As Integer


Type: System.Collections.IDictionary
The row key values for the records to be updated.
Type: System.Collections.IDictionary
The row values to be updated in the data source.
Type: System.Collections.IDictionary
The row values that are evaluated to detect data conflicts.

Return Value

Type: System.Int32
The number of records affected by the update operation.

Typically, you do not have to call the Update method from your code. The data-bound control will automatically call the Update method when the user takes action to update a record. You explicitly call the Update method when you want to create your own process for updating data.

The following example shows how to programmatically update a record in the data source after the user clicks a button. The code passes a ListDictionary object that contains the key value, a ListDictionary object that contains the original values, and a ListDictionary object that contains the new values to the Update method.

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)

End Sub

The following example shows the markup for the previous example.

          runat="server" AutoGenerateRows="False">
          <asp:templatefield HeaderText="Product ID">
					<asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ProductID") %>'></asp:Label>
          	<asp:templatefield HeaderText="Product Name">
					<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("ProductName") %>'></asp:Label>
          	<asp:templatefield HeaderText="Category">
					<asp:Label ID="CategoryLabel" runat="server" Text='<%# Bind("ProductCategory") %>'></asp:Label>
			<asp:templatefield HeaderText="Color">
					<asp:Label ID="ColorLabel" runat="server" Text='<%# Bind("Color") %>'></asp:Label>
          Text="Reset with default values" 
		  onclick="Add_Click" />

.NET Framework

Supported in: 4, 3.5

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.