Solved

VB.net error after conversion from C#

Posted on 2014-01-24
9
369 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:murbro
  • 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 142

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
 
LVL 142

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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 62

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 62

Expert Comment

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

Author Closing Comment

by:murbro
ID: 39811436
Thanks for the help
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now