Skip to main content

Hi,

I need to convert this code in C# to VC. In the link: cs2cobol.microfocuscloud.com/ the conversion has errors.

DataTable table = new DataTable();
table.Columns.Add("Salesman", typeof(string));
table.Columns.Add("ClientID", typeof(int));

//insert your data
table.Rows.Add("Bob", 1);
table.Rows.Add("Bob", 2);
table.Rows.Add("Bob", 3);
table.Rows.Add("Tom", 4);
table.Rows.Add("Joe", 5);
table.Rows.Add("Joe", 6);
table.Rows.Add("Tim", 7);
table.Rows.Add("Tim", 8);

// query with LINQ 
var query = from row in table.AsEnumerable()
            group row by row.Field<string>("Salesman") into sales
            orderby sales.Key
            select new
            {
                Name = sales.Key,
                CountOfClients = sales.Count()
            };

// print result
foreach (var salesman in query)
{
    Console.WriteLine("{0}\\t{1}", salesman.Name, salesman.CountOfClients);
}

VC 6.0
Win64
VS Community 2019
Regards
Borges

Hi,

I need to convert this code in C# to VC. In the link: cs2cobol.microfocuscloud.com/ the conversion has errors.

DataTable table = new DataTable();
table.Columns.Add("Salesman", typeof(string));
table.Columns.Add("ClientID", typeof(int));

//insert your data
table.Rows.Add("Bob", 1);
table.Rows.Add("Bob", 2);
table.Rows.Add("Bob", 3);
table.Rows.Add("Tom", 4);
table.Rows.Add("Joe", 5);
table.Rows.Add("Joe", 6);
table.Rows.Add("Tim", 7);
table.Rows.Add("Tim", 8);

// query with LINQ 
var query = from row in table.AsEnumerable()
            group row by row.Field<string>("Salesman") into sales
            orderby sales.Key
            select new
            {
                Name = sales.Key,
                CountOfClients = sales.Count()
            };

// print result
foreach (var salesman in query)
{
    Console.WriteLine("{0}\\t{1}", salesman.Name, salesman.CountOfClients);
}

VC 6.0
Win64
VS Community 2019
Regards
Borges

Hi Borges,

Sorry but LINQ expressions are not currently supported in Visual COBOL so there is no direct conversion from LINQ syntax to COBOL syntax. For SQL DataTables, etc you would either have to use the standard .NET classes (SqlCommands, etc) or look at using the Visual COBOL support for EXEC ADO statements. There are examples of this in the Samples Browser located in the Visual COBOL folder on the Windows Start menu.