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.
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
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