Visualizzazione dei risultati da 1 a 8 su 8
  1. #1

    [VB.NET] DataTable eliminazione records

    Ciao ho una DataTable dalla quale devo eliminare le righe che hanno determinati campi con valore = 0, ma mi scontro con la logica del mio loop.

    Codice :

    codice:
            For X As Int32 = 0 To tblTot.Rows.Count - 1
                    If CInt(tblTot.Rows(X).Item("LANDA")) = 0 And _
                        CInt(tblTot.Rows(X).Item("SOLD")) = 0 And _
                        CInt(tblTot.Rows(X).Item("AVAIL")) = 0 And _
                        CInt(tblTot.Rows(X).Item("TSOLD")) = 0 And _
                        CInt(tblTot.Rows(X).Item("XSOLD")) = 0 And _
                        CInt(tblTot.Rows(X).Item("SGL")) = 0 And _
                        CInt(tblTot.Rows(X).Item("TRP")) = 0 And _
                        CInt(tblTot.Rows(X).Item("INDEP")) = 0 And _
                        CInt(tblTot.Rows(X).Item("GRDEP")) = 0 And _
                        CInt(tblTot.Rows(X).Item("INOPT")) = 0 And _
                        CInt(tblTot.Rows(X).Item("GROPT")) = 0 And _
                        CInt(tblTot.Rows(X).Item("TWINS")) = 0 And _
                        CInt(tblTot.Rows(X).Item("SFEMS")) = 0 And _
                        CInt(tblTot.Rows(X).Item("SMALS")) = 0 Then
                        tblTot.Rows(X).Delete()
                    End If
            Next
    Quando arriva a 7000 circa, mi dice che il record corrispondente non esiste, questo perchè il COunt delle Rows cambia ogni volta che elimino una riga ...

    Avete qualche suggerimento?

  2. #2
    Utente di HTML.it L'avatar di Brainjar
    Registrato dal
    Nov 2004
    Messaggi
    1,162
    Potresti invertire il controllo dall'ultimo al primo.
    Non ho provato, ma potrebbe essere un'alternativa.
    codice:
     
           For X As Int32 = tblTot.Rows.Count To 0 Step  - 1
                    If CInt(tblTot.Rows(X).Item("LANDA")) = 0 And _
                        CInt(tblTot.Rows(X).Item("SOLD")) = 0 And _
                        CInt(tblTot.Rows(X).Item("AVAIL")) = 0 And _
                        CInt(tblTot.Rows(X).Item("TSOLD")) = 0 And _
                        CInt(tblTot.Rows(X).Item("XSOLD")) = 0 And _
                        CInt(tblTot.Rows(X).Item("SGL")) = 0 And _
                        CInt(tblTot.Rows(X).Item("TRP")) = 0 And _
                        CInt(tblTot.Rows(X).Item("INDEP")) = 0 And _
                        CInt(tblTot.Rows(X).Item("GRDEP")) = 0 And _
                        CInt(tblTot.Rows(X).Item("INOPT")) = 0 And _
                        CInt(tblTot.Rows(X).Item("GROPT")) = 0 And _
                        CInt(tblTot.Rows(X).Item("TWINS")) = 0 And _
                        CInt(tblTot.Rows(X).Item("SFEMS")) = 0 And _
                        CInt(tblTot.Rows(X).Item("SMALS")) = 0 Then
                        tblTot.Rows(X).Delete()
                    End If
            Next
    Ciao,
    Ciao, Brainjar

  3. #3
    Mmm provo e ti faccio sapere.

  4. #4
    Utente di HTML.it L'avatar di Brainjar
    Registrato dal
    Nov 2004
    Messaggi
    1,162
    Scusa, ma doveva essere

    For X As Int32 = tblTot.Rows.Count -1 To 0 Step - 1

    Ciao,
    Ciao, Brainjar

  5. #5
    Si grazie ma è stranissimo pero' ...
    Al contrario comunque il COunt delle Rows diminuisce ogni volta lo stesso ...

    Boh, l' importante è che va.

    Grassie!!


  6. #6
    Utente di HTML.it L'avatar di Brainjar
    Registrato dal
    Nov 2004
    Messaggi
    1,162
    Grazie a te per la fiducia nel provare.
    Il recordCount diminuisce è vero, ma sul record eliminato non ci
    vai più, quindi non ti dà errore.

    Ciao.
    Ciao, Brainjar

  7. #7
    Originariamente inviato da raffaeu
    Boh, l' importante è che va.
    non sarebbe meglio usare una dataview es.
    codice:
    tblTot.DefaultView.RowFilter = "NomeCampo = 0 AND NomeCampo2 = 0 AND ...."
            For Each _drv As DataRowView In tblTot.DefaultView
                _drv.Delete()
            Next
    Saluti a tutti
    Riccardo

  8. #8
    Bravo avevo già risolto ma cosi' almeno metto alla prova anche le DataView!!

    Provo.


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.