Click here to Skip to main content
15,913,091 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Friends

When I Add a new DataRow or Edit one, DataSet.HasChanges() returns true; But when I remove a row it returns false, so DataSet does not update.

I use this code:

C#
long id = long.Parse(this.ListBox.SelectedValue.ToString());

DataSet.CountryRow row = this.DataSet.Country.FindByID(id);

this.DataSet.Country.RemoveCountryRow(row);


Why it happens? Please help me.
Posted
Updated 24-Jul-12 8:46am
v2
Comments
Nueman 24-Jul-12 14:47pm    
Minor corrections

1 solution

I think you need to use row.Delete()

http://msdn.microsoft.com/en-us/library/system.data.datarow.delete[^]

I don't know if you are using a data adapter to update the source database table or not, but thought I'd add this.
Removing the row from the dataset's datatable will not remove the data from the original source database table, however using the delete method will mark it for deletion, so if you use dataadapter.update(dataset) it will delete the rows from database table that are marked for deletion.
 
Share this answer
 
v2
Comments
[no name] 24-Jul-12 15:18pm    
Thanks, it was very helpful.
Just for saying, I know that it needs to update by TableAdapter.
I used to do that when user confirmed it at FormClosing event.
Anyway Thanks Again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900