ADO.NET Projects

ADO.NET Project 1

ADO.NET Examples


Editing Disconnected Data
Previous Home Next

The various objects in ADO.NET that compose the disconnected part of ADO.NET , have ability to make edits or modifications to themselves. there are mainly three kinds of modification operations that can be perform on disconnected data:

  • Add new rows
  • Modify existing rows
  • Delete existing rows

Add New Rows

There are two ways to add a new row to a DataTable, and two ways to add existing rows (from other DataTables or Detached rows) to a DataTable.

  1. The first way assumes thate we have a schema or at least a structure preloaded to the DataTable.


    rowInQuestion = StudentTable.NewRow();
    rowInQuestion["StudentID"] = 4;
    rowInQuestion["SudentName"] = "Ashish";
  2. The second method to add a new DataRow into a DataTable is to use the LoadDataRow method. Load data row method allows you to add a new DataRow and set its various values in one convenient method call.


    object[] rowVals = {"4", "Ashish"} ;
    StudentTable.LoadDataRow(rowVals, false);


Modify Existing Rows

Two methods exist for adding existing DataRows to a DataTable. The first is the ImportRow method, which simply takes a DataRow as a parameter, and the second is the Merge method, which merges two sets of disconnected data (DataSet, DataTable, DataRow array, etc.)

  1. The first way of modifying rows, DataRowState at the end of this edit would be Modified


    rowInQuestion = StudentTable.Rows[0];
    rowInQuestion["StudentName"] = "Anil";
  2. There second way of modifying rows, The DataRow object has a method called BeginEdit,and a matching method called EndEdit.we can modify the rows between these two method calls and difference is that all the changes are buffered until you call EndEdit. If, in case you change your mind, you call CancelEdit instead, all the changes are rolled back.


    rowInQuestion = StudentTable.Rows[0];
    rowInQuestion["StudentName"] = "Aditya";
    rowInQuestion.EndEdit() ;
    rowInQuestion = StudentTable.Rows[0];
    rowInQuestion.ItemArray = new object[] {null, "kamal"} ;

Delete Existing Rows

using delete method we can delete the row

rowInQuestion = StudentTable.Rows[1];

Another way of removing a row is by using either the Remove or RemoveAt method on the DataRowCollection object (DataTable.Rows is of DataRowCollection type)

StudentTable.Remove(rowInQuestion) ;
// or
StudentTable.RemoveAt(1) ;

The DataRowVersion Enumeration Description
Current This will give you the current value stored inside a column.
Original This allows you to fetch the original value stored inside a column.
Proposed This allows you to fetch the proposed value after a BeginEdit and update but before an EndEdit.
Default This retrieves the value as if the wasn’t specified
Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Comment / Feedback: