dotConnect for DB2 Documentation
Devart.Common Namespace / DbDataTable Class / UpdateRows Method
An array of System.Data.DataRow objects containing the rows to be updated.
Example

In This Topic
    UpdateRows Method
    In This Topic
    Executes the appropriate commands to delete, insert, or update the specified rows in the data source.
    Syntax
    'Declaration
     
    Public Function UpdateRows( _
       ByVal datarows() As DataRow _
    ) As Integer
    public int UpdateRows( 
       DataRow[] datarows
    )

    Parameters

    datarows
    An array of System.Data.DataRow objects containing the rows to be updated.

    Return Value

    The number of rows successfully updated from the DbDataTable.
    Remarks
    Using this method may result in performance gains, for example, on very big tables. If the CachedUpdates property is false, the method does nothing, because changes are applied instantly.
    Example
    The following code adds two records to a table and updates them. The table is rendered then to console.
    static void UpdateATable(DbDataTable myDataTable, IDbConnection myConnection)
    {
      myDataTable.Connection = myConnection;
      myDataTable.SelectCommand = myConnection.CreateCommand();
      myDataTable.SelectCommand.CommandText = "SELECT EmpNo, EName FROM Emp";
      try
      {
        myDataTable.Active = true;
        DataRow[] newRows = new DataRow[2];
        newRows[0] = myDataTable.Rows.Add(new object[] {20000,"Jefferson"});
        newRows[1] = myDataTable.Rows.Add(new object[] {20001,"Jameson"});
        myDataTable.UpdateRows(newRows);
    
        foreach(DataRow myRow in myDataTable.Rows)
        {
          foreach(DataColumn myCol in myDataTable.Columns)
          {
            Console.Write(myRow[myCol]+"\t");
          }
          Console.WriteLine();
        }
      }
      finally
      {
        myDataTable.Active = false;
      }
    }
    Public Sub UpdateATable(ByVal myDataTable As DbDataTable, ByVal myConnection As IDbConnection)
      myDataTable.Connection = myConnection
      myDataTable.SelectCommand = myConnection.CreateCommand()
      myDataTable.SelectCommand.CommandText = "SELECT EmpNo, EName FROM Emp"
      Try
        myDataTable.Active = True
        Dim newVal1() As Object = {20000, "Jefferson"}
        Dim newVal2() As Object = {20001, "Jameson"}
        Dim newRows(1) As DataRow
        newRows(0) = myDataTable.Rows.Add(newVal1)
        newRows(1) = myDataTable.Rows.Add(newVal2)
        myDataTable.UpdateRows(newRows)
    
        Dim myRow As DataRow
        Dim myCol As DataColumn
        For Each myRow In myDataTable.Rows
          For Each myCol In myDataTable.Columns
            Console.Write(myRow(myCol) & Chr(9))
          Next myCol
          Console.WriteLine()
        Next myRow
      Finally
        myDataTable.Active = False
      End Try
    End Sub
    Requirements

    Target Platforms: 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

    See Also