SqlDataSourceView.Update Method (IDictionary, IDictionary, IDictionary)

Performs an update operation using the UpdateCommand SQL string, any parameters that are in the UpdateParameters collection, and the values that are in the specified keys, values, and oldValues collections.

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

public:
int Update (
	IDictionary^ keys, 
	IDictionary^ values, 
	IDictionary^ oldValues
)
public int Update (
	IDictionary keys, 
	IDictionary values, 
	IDictionary oldValues
)
public function Update (
	keys : IDictionary, 
	values : IDictionary, 
	oldValues : IDictionary
) : int
Not applicable.

Parameters

keys

An IDictionary of primary keys to use with the UpdateCommand property to perform the update database operation. If there are no keys associated with the query or if the UpdateCommand is not a parameterized SQL query, pass a null reference (Nothing in Visual Basic).

values

An IDictionary of values to use with the UpdateCommand property to perform the update database operation. If there are no parameters associated with the query or if the UpdateCommand is not a parameterized SQL query, pass a null reference (Nothing in Visual Basic).

oldValues

An IDictionary that represents the original values in the database. If there are no parameters associated with the query or if the UpdateCommand is not a parameterized SQL query, pass a null reference (Nothing in Visual Basic).

Return Value

A value that represents the number of rows updated in the underlying database.

Exception typeCondition

InvalidOperationException

The SqlDataSource cannot establish a connection with the underlying data source.

NotSupportedException

The CanUpdate property is false.

The Update method calls the ExecuteUpdate method, passing the keys, values, and oldValues parameters. For more information, see SqlDataSource.UpdateCommand.

The following code example demonstrates how to use a SqlDataSource control to display data in a DropDownList control and update data when the Submit button is clicked. The UpdateCommand property is set with a parameterized SQL statement and two ControlParameter parameters are added to the UpdateParameters collection. When the Submit button is clicked, the OnClick event is handled to call the Update method explicitly.

No code example is currently available or this language may not be supported.
<%@Page  Language="VJ#" %>
<!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, System.EventArgs e)
 {
    try {
       SqlDataSource1.Update();
    }
    catch (Exception except) {
        // Handle the Exception.
    }
    Label2.set_Text("The record was updated successfully!");
 } //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="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;"
          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>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: