Dopo attenta riflessione ed il weekend rovinato su righe e colonne (a cena da amici pensavo all'aggiunta delle datarow) ho concluso che il modo piu' veloce e' questo, in Pietro-Style:
(all'inizio volevo fare un array di DataRow e poi ciclando in esso importarle nel datatable finale con NomeDataTable.ImportRow)
Il secondo parametro visualizza o meno la testata con i nomi dei campi...
codice:Public Function DataTableOrizzontale(ByVal dt As DataTable, ByVal AggiungiTestataVerticale As Boolean) As DataTable Dim DataTableGirato As New DataTable Dim indR As Integer = 0 If AggiungiTestataVerticale = True Then Dim NomiCampi As New DataColumn NomiCampi.ColumnName = "NOME CAMPO" NomiCampi.DataType = GetType(String) DataTableGirato.Columns.Add(NomiCampi) End If ' Preparo le colonne For Each riga As DataRow In dt.Rows Dim nuovacolonna As New DataColumn("COLONNA " & CStr(indR), GetType(String)) DataTableGirato.Columns.Add(nuovacolonna) indR += 1 Next For indColonne As Integer = 0 To dt.Columns.Count - 1 Dim nuovariga As DataRow = DataTableGirato.NewRow() Dim indPartenzaRighe = 0 If AggiungiTestataVerticale = True Then nuovariga(0) = "" & LCase(dt.Columns(indColonne).ColumnName) & "" indPartenzaRighe = 1 End If For indRighe As Integer = 0 To dt.Rows.Count - 1 nuovariga(indPartenzaRighe) = dt.Rows(indRighe)(indColonne) indPartenzaRighe += 1 Next DataTableGirato.Rows.Add(nuovariga) Next DataTableOrizzontale = DataTableGirato End Function
Per sdebitarmi della logica ti posto una funzione che ho fatto per esplorare un dataset prima di Bindarlo ad una griglia, magari va in libreria anche questa![]()
(basta usarlo con: libreria.esplora_dataset(nomedataset))
L'idea di Little Wood pero' non e' male. Cd Rom Asp.Net -tips dal mondo reale-codice:Public Shared Sub esplora_dataset(ByVal ds As DataSet) HttpContext.Current.Response.Write("<div style=""WIDTH:100%; BORDER-RIGHT: red thin solid; BORDER-TOP: red thin solid; BORDER-LEFT: red thin solid; BORDER-BOTTOM: red thin solid; BACKGROUND-COLOR: #fffff0""><center>NOME DATASET: " & ds.DataSetName) Dim iTabelle As Integer Dim iRighe As Integer Dim iColonne As Integer For iTabelle = 0 To ds.Tables.Count - 1 ' Nome della tabella corrente HttpContext.Current.Response.Write("<div style=""WIDTH:90%; BORDER-RIGHT: red thin solid; BORDER-TOP: red thin solid; BORDER-LEFT: red thin solid; BORDER-BOTTOM: red thin solid; BACKGROUND-COLOR: #ffffcc""><u>TABELLA: " & ds.Tables(iTabelle).TableName & "</u>") For iRighe = 0 To ds.Tables(iTabelle).Rows.Count - 1 HttpContext.Current.Response.Write(" <font color=red>RIGA N. " & iRighe & "</font> ") For iColonne = 0 To ds.Tables(iTabelle).Columns.Count - 1 HttpContext.Current.Response.Write("<u>NOME COLONNA</u>: " & UCase(ds.Tables(iTabelle).Columns(iColonne).ColumnName) & "<font color=red>/</font>") HttpContext.Current.Response.Write("<u>VALORE</u>: " & ds.Tables(iTabelle).Rows(iRighe)(iColonne) & " ") Next Next HttpContext.Current.Response.Write("</div> ") Next HttpContext.Current.Response.Write("</center></div>") End Sub
Il best dei programmatori di Html.it![]()

) ho concluso che il modo piu' veloce e' questo, in Pietro-Style:
Rispondi quotando