Murray Brown
asked on
VB.net Reference for Pivot class
Hi
In VB.net what do I have to reference to use the Pivot class with code like the following
and can this be used in ASP.net:
Public Function PivotData(RowField As String, DataField As String, Aggregate As AggregateFunction, ParamArray ColumnFields As String()) As DataTable
Dim dt As New DataTable()
Dim Separator As String = "."
Dim RowList = (From x In _SourceTable.AsEnumerable( )New With { _
Key .Name = x.Field(Of Object)(RowField) _
}).Distinct()
Dim ColList = (From x In _SourceTable.AsEnumerable( )New With { _
Key .Name = ColumnFields.[Select](Func tion(n) x.Field(Of Object)(n)).Aggregate(Func tion(a, b) a += Separator & b.ToString()) _
}).Distinct().OrderBy(Func tion(m) m.Name)
dt.Columns.Add(RowField)
For Each col As var In ColList
dt.Columns.Add(col.Name.To String())
Next
For Each RowName As var In RowList
Dim row As DataRow = dt.NewRow()
row(RowField) = RowName.Name.ToString()
For Each col As var In ColList
Dim strFilter As String = (RowField & Convert.ToString(" = '")) + RowName.Name + "'"
Dim strColValues As String() = col.Name.ToString().Split( Separator. ToCharArra y(), StringSplitOptions.None)
For i As Integer = 0 To ColumnFields.Length - 1
strFilter += " and " + ColumnFields(i) + " = '" + strColValues(i) + "'"
Next
row(col.Name.ToString()) = GetData(strFilter, DataField, Aggregate)
Next
dt.Rows.Add(row)
Next
Return dt
End Function
In VB.net what do I have to reference to use the Pivot class with code like the following
and can this be used in ASP.net:
Public Function PivotData(RowField As String, DataField As String, Aggregate As AggregateFunction, ParamArray ColumnFields As String()) As DataTable
Dim dt As New DataTable()
Dim Separator As String = "."
Dim RowList = (From x In _SourceTable.AsEnumerable(
Key .Name = x.Field(Of Object)(RowField) _
}).Distinct()
Dim ColList = (From x In _SourceTable.AsEnumerable(
Key .Name = ColumnFields.[Select](Func
}).Distinct().OrderBy(Func
dt.Columns.Add(RowField)
For Each col As var In ColList
dt.Columns.Add(col.Name.To
Next
For Each RowName As var In RowList
Dim row As DataRow = dt.NewRow()
row(RowField) = RowName.Name.ToString()
For Each col As var In ColList
Dim strFilter As String = (RowField & Convert.ToString(" = '")) + RowName.Name + "'"
Dim strColValues As String() = col.Name.ToString().Split(
For i As Integer = 0 To ColumnFields.Length - 1
strFilter += " and " + ColumnFields(i) + " = '" + strColValues(i) + "'"
Next
row(col.Name.ToString()) = GetData(strFilter, DataField, Aggregate)
Next
dt.Rows.Add(row)
Next
Return dt
End Function
ASKER
Hi
Thanks. I aleady have System.Data but not sure what you mean by LINQ.
Where would I find the LINQ reference?
Thanks. I aleady have System.Data but not sure what you mean by LINQ.
Where would I find the LINQ reference?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi
Thanks very much
I still have 23 errors
eg Error 34 Type 'AggregateFunction' is not defined. C:\Users\murbro\Documents\ Visual Studio 2010\Projects\Elements\Ele ments\Pivo t.vb 40 82 Elements
Error 33 'RowList' is not declared. It may be inaccessible due to its protection level. C:\Users\murbro\Documents\ Visual Studio 2010\Projects\Elements\Ele ments\Pivo t.vb 23 36 Elements
Error 49 'GetSum' is not declared. It may be inaccessible due to its protection level. C:\Users\murbro\Documents\ Visual Studio 2010\Projects\Elements\Ele ments\Pivo t.vb 61 28 Elements
Thanks very much
I still have 23 errors
eg Error 34 Type 'AggregateFunction' is not defined. C:\Users\murbro\Documents\
Error 33 'RowList' is not declared. It may be inaccessible due to its protection level. C:\Users\murbro\Documents\
Error 49 'GetSum' is not declared. It may be inaccessible due to its protection level. C:\Users\murbro\Documents\
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for murbro's comment #a39805956
for the following reason:
Thanks very much
Accepted answer: 0 points for murbro's comment #a39805956
for the following reason:
Thanks very much
I could not find a standard class having this as type, so I must presume that either it's a typo in the code, or you have some customer class (missing in this project)
huh?
I see you other question now, and I confirm the conversion is incorrect.
it must be:
it must be:
Public Function PivotData(RowField As String, DataField As String, AggregateFunction as Aggregate , ParamArray ColumnFields As String()) As DataTable
ASKER
Thanks. Thought I had already accepted this. Sorry about the delay
System.Data class and the LINQ reference.