Question

I am deleting a row in DataGridView and this Datgridview is bind to a datatable (dt). After deleting the row. The data of that row in the data table is deleted and showing errors.

Was it helpful?

Solution

There are several way to accomplish this. One quick way is to create a data view instance out of the modified data table (data table after delete) and then call ToTable() method on that dataview. This will give us the original data.

DataView view= new DataView(yourTable, null, null, DataViewRowState.Deleted);
DataTable resultTable = view.ToTable();

Another approach would be

var rows=YourTable.Select(); // I assume your name of the table as YourTable and you can change it the way you want

foreach(var row in rows)
{
  if (row.RowState == DataRowState.Deleted)
{
   var splr_Cntctnm = (string)row["splr_Cntctnm", DataRowVersion.Original];
   //you can access all deleted field information as above
}

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top