#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Montreal, Canada
    Posts
    486
    Rep Power
    12

    Reading dataset with a datarow when Removing 2 item ? bug ?


    I don't understand that. I am working on a fonction that is removing item in a BD that is not suppose to be there.

    Everything look like is working find and the code look correct. But the bug happens when I remove 2 items in it and then try to continu to read with a datarow in the dataset.
    It won't let me telling me that the line I am trying to access doesn't exist. How can it not exist ? I am going to the next one and I haven't deleted that one, IMO it's kinda stupid no ?

    here is my code.
    The problem is at the end of the code.

    Code:
            'Déclare le DataSet des rues
            Dim dsDataSetRue As DataSet = frmItems.DataSetRue1.Copy
            'Déclare le DataSet des adresses
            Dim dsDataSetAdresse As DataSet = frmItems.DataSetAdresse1
            'Déclare le DataSet des villes
            Dim dsDataSetVille As DataSet = frmItems.DataSetVille1.Copy
            'Déclare une ligne dans la table des adresse
            Dim drDataRowAdresse As DataRow
            'Déclare une ligne dans la table des rues
            Dim drDataRowRue As DataRow
            'Déclare un objet pour la rue
            Dim objRue As Object
            'Déclare une variable pour savoir si élément trouvé
            Dim btrouve As Boolean = False
            'déclare un tableau qui aura les numéro de rue des rue du combobox
            Dim tabNoRue(cboRue.Items.Count) As Integer
            Dim i As Integer = 0
            'Declare un compteur pour savoir où on est ds la table
            Dim iIndex As Integer = 0
    Code:
                iIndex = 0
                For Each drDataRowAdresse In dsDataSetAdresse.Tables("Adresse").Rows
    
                    If drDataRowAdresse.Item("noreleve") = FindReleve(NoReleve) Then
    
                        'pour chaque element du tableau
                        For i = 1 To (tabNoRue.Length - 1)
    
                            'Si le numéro de la rue est correspondant a l'un des élément
                            If drDataRowAdresse.Item("norue") = tabNoRue(i) Then
                                btrouve = True
                                Exit For
                            End If
    
                        Next i
    
                        'Si l'élément n'est plus dans la liste
                        If btrouve = False Then
                            'Enlève de la DB la donnée se trouvant a l'iIndex
                            frmItems.BindingContext(frmItems.DataSetAdresse1, "Adresse").RemoveAt(iIndex)
    
                        Else : btrouve = False
                        End If
    
                    End If
    
                    'Ajoute 1 a l'index pour trouver l'élement où on est rendu
                    iIndex = iIndex + 1
    
                Next
                'Force le programme a faire un update des données
                Try
                    frmItems.OleDbDataAdapterAdresse.Update(frmItems.DataSetAdresse1)
                Catch
                    MsgBox("Erreur pendant l'enregistrement des données de la table 'ADRESSE'.", MsgBoxStyle.Exclamation + MsgBoxStyle.OKOnly, _
                                                                                                                        "Gestion des relevés")
                End Try
            Else
                'Affiche d'un message d'erreur s'il n'y a pas de rue d'ajouter
                MsgBox("Vous devez avoir au moins une rue pour chaque relevé", MsgBoxStyle.OKOnly, "Gestion des relevés")
            End If
    
    
        End Sub
    I have put in bold the place where I remove the item. and the bug happens when it's hits the NEXT of the for.
    I also tryed to make a database update but still won't work.

    BTW : don't tell me the function is ugly and bad programming, I already know that. I am thinking of doing it all again but it would be long and I don't know how to really do it soo that if there is more then 1 user working on the database it's doesn't bug.
    but I dope that I have other choice one of those days cause it's take to much time to do the function.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Montreal, Canada
    Posts
    486
    Rep Power
    12
    nobody ever got something like that I should assume ?

IMN logo majestic logo threadwatch logo seochat tools logo