Hi all![]()
What is the best method to update a data row, here what I am doing is searching the row from the datatable , then deleting the row and after modifying the row adding the row again.
But I am getting error when I am trying to delete the row the error saying that
This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row.
basically I want to update a datarow in the datatable according to the condition.
Thanks
Code is as below
C# Code:
DataTable dataTable = userTrackingProcess.PageDetail; DataTable saveDataTable = GetStructure(); //STURCTURE OF BOTH DATATABLE ARE SAME string lastPageName=string.Empty; try { SessionPage sessionPage = new SessionPage(); foreach (DataRow dataRow in dataTable.Rows) { Browser = (string)userTrackingProcess.Browser.ToString(); if (!(lastPageName.Equals(string.Empty))) { if (!lastPageName.Equals(dataRow["Page_URL"].ToString())) { DataRow[] row; row = saveDataTable.Select("Page_URL='" + lastPageName + "'"); if (row.Length >= 0) { saveDataTable.Rows.Remove(row[0]); saveDataTable.AcceptChanges(); row[0]["End_Time"] = (DateTime)row[0]["End_Time"]; saveDataTable.ImportRow(dataRow); } saveDataTable.ImportRow(dataRow); } else { DataRow[] row; row = saveDataTable.Select("Page_URL='" + lastPageName + "'"); if (row.Length >= 0) { saveDataTable.Rows.Remove(row[0]); saveDataTable.AcceptChanges(); row[0]["Total_Hit"] = (int)row[0]["Total_Hit"] + 1; saveDataTable.ImportRow(dataRow); } } } else { saveDataTable.ImportRow(dataRow); } lastPageName = saveDataTable.Rows[saveDataTable.Rows.Count - 1]["Page_URL"].ToString(); saveDataTable.AcceptChanges(); } //SAVING THE DATA IN THE DATABSE if (saveDataTable.Rows.Count > 0) { } } catch { throw; }




Reply With Quote