Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.net Reference for Pivot class

Posted on 2014-01-24
9
Medium Priority
?
530 Views
Last Modified: 2014-01-27
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](Function(n) x.Field(Of Object)(n)).Aggregate(Function(a, b) a += Separator & b.ToString()) _
      }).Distinct().OrderBy(Function(m) m.Name)

        dt.Columns.Add(RowField)
        For Each col As var In ColList
            dt.Columns.Add(col.Name.ToString())
        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.ToCharArray(), 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
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39805933
from what I see you need not that much :
System.Data class and the LINQ reference.
0
 

Author Comment

by:Murray Brown
ID: 39805956
Hi

Thanks. I aleady have System.Data but not sure what you mean by LINQ.
Where would I find the LINQ reference?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 39805960
from the official reference:
http://msdn.microsoft.com/en-us/library/bb546156.aspx 
To enable basic LINQ functionality

    In a Visual Basic or C# project, click the Project menu, and then click Add Reference.

    In the Add Reference dialog box, click the .NET tab, scroll to System.Core.dll, and then click it. Click OK.

    Add a using directive or Imports statement for System.Linq to your source code file or project.

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Murray Brown
ID: 39805972
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\Elements\Pivot.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\Elements\Pivot.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\Elements\Pivot.vb      61      28      Elements
0
 

Author Comment

by:Murray Brown
ID: 39806018
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
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39806012
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)
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39806014
huh?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39806019
I see you other question now, and I confirm the conversion is incorrect.
it must be:
Public Function PivotData(RowField As String, DataField As String, AggregateFunction as Aggregate  , ParamArray ColumnFields As String()) As DataTable 

Open in new window

0
 

Author Closing Comment

by:Murray Brown
ID: 39811432
Thanks. Thought I had already accepted this. Sorry about the delay
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question