Results 1 to 4 of 4

Thread: Getting Error: Collection was modified enumeration operation might not execute

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Posts
    1

    Getting Error: Collection was modified enumeration operation might not execute

    Hi iam getting the following Error: "Collection was modified enumeration operation might not execute"

    The Error accures on the following source Code:

    First:

    Code:
    Txtbox.ID = "txt_" + i.ToString
                        Txtbox.Attributes("Style") = "border-top: 0px solid Gray;border-bottom: 0px solid Gray;border-left: 0px solid Gray;border-right: 0px solid Gray;"
                        Txtbox.Font.Underline = True
                        Txtbox.Font.Size = System.Web.UI.WebControls.FontUnit.Point(8)
                        Txtbox.Width = System.Web.UI.WebControls.Unit.Pixel(140)
                        Dim drow() As DataRow = Nothing
                        If (Not dataTable Is Nothing) Then
                            If (dataTable.Rows.Count <> 0) Then
                                drow = dataTable.Select("column2='" + Txtbox.Text + "'")  <--- that line is throwing the Error!
                            End If
                        End If
    Second:

    Code:
    If (Not Session("MailTable") Is Nothing) Then
                    Dim dataTable As DataTable = Session("MailTable")
                    Dim drow() As DataRow
                    drow = dataTable.Select("column1='" + txtVerEmail.Text + "'")  <--- That line is throwing the Error!
                    If (drow.Count <> 0) Then
                        ResourcesList.Value = drow(0).Item(1) + ";"
                    Else
                        ResourcesList.Value = txtVerEmail.Text + ";"
                    End If
                Else
                    ResourcesList.Value = txtVerEmail.Text + ";"
                End If

    What does the Error mean and how can i fix it?


    Thanks in advance

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,943

    Re: Getting Error: Collection was modified enumeration operation might not execute

    The error has to do with code that you didn't show us. I would expect that somewhere prior to each line you deleted a row from the datatable.
    My usual boring signature: Nothing

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Getting Error: Collection was modified enumeration operation might not execute

    Have you, by chance, declared dataTable globally (I strongly advise you to get out of the habit of calling variables by the same name as the type anyway!) and then re-dimmed? If Session("MailTable") is a valid DataTable why assign it to another variable at all? This assignment doesn't work anyway. To copy a dtatable you need .Clone? Are your datatable columns actually called column1 and column2?
    Last edited by dunfiddlin; Oct 2nd, 2012 at 10:07 AM.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Getting Error: Collection was modified enumeration operation might not execute

    Another double post!
    Last edited by dunfiddlin; Oct 2nd, 2012 at 10:05 AM.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width