Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Delete a record from the dataset

Delete a record from the dataset

Scheduled Pinned Locked Moved C#
helpannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chandragupta k
    wrote on last edited by
    #1

    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); } }

    V C 2 Replies Last reply
    0
    • C chandragupta k

      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); } }

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=474992&SiteID=1[^]

      Vasudevan Deepak Kumar Personal Homepage Tech Gossips

      C 1 Reply Last reply
      0
      • C chandragupta k

        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); } }

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        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 )

        1 Reply Last reply
        0
        • V Vasudevan Deepak Kumar

          http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=474992&SiteID=1[^]

          Vasudevan Deepak Kumar Personal Homepage Tech Gossips

          C Offline
          C Offline
          chandragupta k
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups