Ho un DataSet
denominato DataSet1
. Contiene un numero sconosciuto di tabelle e un numero sconosciuto di colonne e righe in quelle tabelle. Vorrei scorrere ogni tabella e osservare tutti i dati in ogni riga per ogni colonna. Non sono sicuro di come codificarlo. Qualsiasi aiuto sarebbe apprezzato!Iterate through DataSet
risposta
Proprio anello ...
foreach(var table in DataSet1.Tables) {
foreach(var col in table.Columns) {
...
}
foreach(var row in table.Rows) {
object[] values = row.ItemArray;
...
}
}
Sono confuso .. questo codice eseguirà il loop delle colonne, quindi passerà attraverso le righe .. –
Penso che @Marc stia dimostrando che è possibile eseguire il loop delle colonne: non è necessario se sei solo interessato i valori delle righe, ma se si iterano le colonne è possibile stampare le intestazioni delle colonne che potrebbero essere utili. – RobertMS
@PhillipSchmidt piuttosto tipico se, per esempio, si desidera stampare le intestazioni delle colonne ecc. –
foreach (DataTable table in dataSet.Tables)
{
foreach (DataRow row in table.Rows)
{
foreach (object item in row.ItemArray)
{
// read item
}
}
}
Oppure, se avete bisogno di informazioni di colonna:
foreach (DataTable table in dataSet.Tables)
{
foreach (DataRow row in table.Rows)
{
foreach (DataColumn column in table.Columns)
{
object item = row[column];
// read column and item
}
}
}
- 1. Iterate through 2 Lists
- 2. While Loop to Iterate through Database
- 3. Python Django Template: Iterate Through List
- 4. rails has_many: through has_many: through
- 5. Rails polymorphic has_many: through
- 6. C#: Cycle through encodings
- 7. loop through JPanel
- 8. activerecord find through association
- 9. Iterating through viewgroup
- 10. Django M2MFields 'through' widgets
- 11. Python 'except' fall-through
- 12. loop through sottocartelle
- 13. Has_Many: Through o: finder_sql
- 14. jQuery loop through json?
- 15. Cycle Through Divs
- 16. NSTextField click-through?
- 17. Iterating through array - java
- 18. Firebug CSS strike-through
- 19. Strike through java.awt.Font
- 20. C++ Loop through Map
- 21. Spark Dataset API - join
- 22. Aggiornamento dataset h5py
- 23. dataset vs .data - Differenza?
- 24. Dataset Twitter (Social networking)
- 25. Classe DataSet in Java?
- 26. Convert to XML Dataset
- 27. Enum in DataSet
- 28. Iterate attraverso l'hashmap nidificato
- 29. backbone.js iterate una raccolta
- 30. Iterate over nested dictionary
Si prega di indicare una risposta. – jipje44