Solved

VB.net error after conversion from C#

Posted on 2014-01-24
9
372 Views
Last Modified: 2014-01-27
Hi. I converted the C# code at the bottom to get the VB.net code below but the system
is showing a few errors. For instance in the row market ERROR I get the message
')' expected

    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 { _  'ERROR
            Key .Name = x.Field(Of Object)(RowField) _
      }).Distinct()



public DataTable PivotData(string RowField, string DataField,
       AggregateFunction Aggregate, params string[] ColumnFields)
{
    DataTable dt = new DataTable();
    string Separator = ".";
    var RowList = (from x in _SourceTable.AsEnumerable()
        select new { Name = x.Field<object>(RowField) }).Distinct();
    var ColList = (from x in _SourceTable.AsEnumerable()
                   select new { Name = ColumnFields.Select(n => x.Field<object>(n))
                       .Aggregate((a, b) => a += Separator + b.ToString()) })
                       .Distinct()
                       .OrderBy(m => m.Name);
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
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 13

Accepted Solution

by:
Alexander Eßer [Alex140181] earned 250 total points
ID: 39806034
Have you tried this (untested)?!
	 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() Select New With { Key .Name = x.Field(Of Object)(RowField)  }).Distinct()

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39806040
Aggregate As AggregateFunction  must be AggregateFunction As Aggregate
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 39806090
Aggregate As AggregateFunction  must be AggregateFunction As Aggregate
I doubt it, it has to be from Microsoft Dynamics AX... (http://msdn.microsoft.com/en-us/library/microsoft.dynamics.ax.framework.workflow.model.axqueryservicereference.aggregatefunction.aspx)
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39806102
sorry, but there AggregateFunction you refer to is is a Enum, and looking at the code I doubt that would do it, as it tries to "use" the "function" indeed.

anyhow, reading another question from the asker, this code was converted from C# to vb.net, and the conversion did not work correctly, and the Aggregate is simply a LINQ "type"
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 39806106
Sorry, I was just too quick on that to respond :-( My bad...
0
 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 total points
ID: 39806847
Hi Alexander Eßer;

See if this code snippet get you any closer.

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() _
                   Select New With _
                   { _
                       .Name = x.Field(Of Object)(RowField) _
                   }).Distinct()
                   
    var ColList = (From x in _SourceTable.AsEnumerable() _
                   Select New With _
                   { _
                   	   .Name = ColumnFields.Select(Function(n) x.Field(Of Object)(n)) _
                                           .Aggregate(Function(a, b) a &= Separator & b.ToString()) _
                   }).Distinct() _
                     .OrderBy(Function(m) m.Name)
                   
End Function  

Open in new window

0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 39807961
That's too kind,  Fernando, but it's not me who's asking ;-)
Thanks anyways...
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39807996
Sorry, that should have been murbro.
0
 

Author Closing Comment

by:Murray Brown
ID: 39811436
Thanks for the help
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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