Arrao4u

…a blog by Rama Rao

Archive for the ‘Modifying Datatable’ Category

Modifying data table

Posted by arrao4u on December 26, 2009

Modifying data into DataTable

Modifying Row Data

To edit the data of the row, sets its column value using row index or by specifying the column name. In below example, I am updating the 3rd row of the DataTable as I have specified the row index as 2 (dTable.Rows[2]).

// modify certain values into the DataTable

dTable.Rows[2][“AutoID”] = 20;

dTable.Rows[2][“Name”] = “Modified”;

dTable.Rows[2][“Address”] = “Modified Address”;

dTable.AcceptChanges();

Deleting Row

To delete a row into DataTable, call the rows.Delete() method followed by AcceptChanges() method. AcceptChanges() method commits all the changes made by you to the DataTable. Here Row[1] is the index of the row, in this case 2nd row will be deleted as in collection (here rows collection) count start from 0.

// Delete row

dTable.Rows[1].Delete();

dTable.AcceptChanges();

Posted in Datatable, Modifying Datatable | Leave a Comment »