Re: [2.0] Update a datarow
First of all, you're not deleting the row; you're removing it. Deleting a DataRow and removing it are two different things.
Second, why are you removing it and add it back if all you want to do is update it? If all you want to do is update it then that's all you should do.
Third, if you really must remove the row for some reason then the very error message you posted is already telling you what to do:
Quote:
This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row.
Do you want to create new data in that row? If so then do what it says and call BeginEdit.
Re: [2.0] Update a datarow
Simplly say that I want to search a data row in the datatable and if found then I want to update it.
Thanks for the reply
Re: [2.0] Update a datarow
If you want to set a field in a row then just do so. You don't have to remove it first. In fact, as you've seen, removing the row discards all the data it contains.
Re: [2.0] Update a datarow
C# Code:
DataRow[] row;
row = saveDataTable.Select("Page_URL='" + lastPageName + "'");
if (row.Length >= 0)
{
saveDataTable.Rows.Remove(row[0]);
saveDataTable.AcceptChanges();
row[0].BeginEdit();
row[0]["Total_Hit"] = row[0]["Total_Hit"].ToString() + 1;
saveDataTable.ImportRow(dataRow);
row[0].EndEdit();
}
Above code is working for me , but is there is any direct way to update the datarow.. I am removing the datarow and adding it again.
Thanks
Re: [2.0] Update a datarow
Consider this. You have an egg carton with an egg in it. You take the egg out, paint it then put it back. Now you say "I want to paint the egg again but this time without taking it out of the carton and putting it back again". What would you do? Wouldn't you just paint the egg in the egg carton without removing it first and putting it back again afterwards? Would you even have to ask?
Now, you've got a DataTable with a DataRow in it. You take the DataRow out, edit it and then put it back. Now you say "I want to edit the DataRow but this time without taking it out of the DataTable and putting it back again". What do you do?