Delete a record from the dataset
-
Hi all, i am trying to delete a row from dataset ,i have used the following code but i am getting error like An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll Additional information: Collection was modified; enumeration operation may not execute. foreach(DataRow dreach in MailDataset.Tables[0].Rows) { if(Convert.ToInt16(dreach["Mailid"])== 37) { dreach.Delete(); MailDataset.AcceptChanges(); MailDataset=MailDataset ; sd1=MailDataset.Tables[0].Rows.Count; //Da.Update(MailDataset); } }
-
Hi all, i am trying to delete a row from dataset ,i have used the following code but i am getting error like An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll Additional information: Collection was modified; enumeration operation may not execute. foreach(DataRow dreach in MailDataset.Tables[0].Rows) { if(Convert.ToInt16(dreach["Mailid"])== 37) { dreach.Delete(); MailDataset.AcceptChanges(); MailDataset=MailDataset ; sd1=MailDataset.Tables[0].Rows.Count; //Da.Update(MailDataset); } }
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=474992&SiteID=1[^]
Vasudevan Deepak Kumar Personal Homepage Tech Gossips
-
Hi all, i am trying to delete a row from dataset ,i have used the following code but i am getting error like An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll Additional information: Collection was modified; enumeration operation may not execute. foreach(DataRow dreach in MailDataset.Tables[0].Rows) { if(Convert.ToInt16(dreach["Mailid"])== 37) { dreach.Delete(); MailDataset.AcceptChanges(); MailDataset=MailDataset ; sd1=MailDataset.Tables[0].Rows.Count; //Da.Update(MailDataset); } }
You often cannot delete items from a collection that you're doing a foreach on. I usually build a list of items to delete, then iterate over that list, to do the deleting.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=474992&SiteID=1[^]
Vasudevan Deepak Kumar Personal Homepage Tech Gossips
Hi Deepak Kumar The url send by you is used to delete a row from hash table but my requirement is that i need to delete a row from dataset Thnaks in Advanc Gupta