Click here to Skip to main content
15,877,966 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello People,

I have made a little code that export all company names of our DB.
I want to create one list that each result is an object in the list.

Could someone help me?

I made this code but I don't get what is wrong.

see code below:



C#
public class Company
    {

        public IEnumerable<Company> CompanyN(int Cname)
        {
            myDB tdc = new myDb();
            var Result= tdc.ExecuteQuery<Company>(@"SELECT TOP (10) [t0].[Id], [t0].[IdAnonymous], [t0].[Name], [t0].[Address1], [t0].[Address2], [t0].[PostalCode], [t0].[City], [t0].[Country], [t0].[Phone], [t0].[Fax], [t0].[Email], [t0].[Web], [t0].[VAT], [t0].[Agreement], [t0].[AgreementEndDate], [t0].[TradosTM], [t0].[PathRefMaterial], [t0].[PaymentTerms], [t0].[Owner], [t0].[CreationDate], [t0].[PriceListName], [t0].[Currency], [t0].[IsActive], [t0].[LogoBlob]FROM [CompanyMain] AS [t0]");
            return Result.ToList();
            foreach (var c in Result)
            {
                Console.WriteLine(c);
            }

        }



Could someone help me?

I get this error:
Unreachable code detected.

Thank you in advance.
Posted

1 solution

You are exiting from function before iterating the list. Try to put
C#
return Result.ToList();

as last statement of the function.
C#
public class Company
{

    public IEnumerable<Company> CompanyN(int Cname)
    {
        myDB tdc = new myDb();
        var Result= tdc.ExecuteQuery<Company>(@"SELECT TOP (10) [t0].[Id], [t0].[IdAnonymous], [t0].[Name], [t0].[Address1], [t0].[Address2], [t0].[PostalCode], [t0].[City], [t0].[Country], [t0].[Phone], [t0].[Fax], [t0].[Email], [t0].[Web], [t0].[VAT], [t0].[Agreement], [t0].[AgreementEndDate], [t0].[TradosTM], [t0].[PathRefMaterial], [t0].[PaymentTerms], [t0].[Owner], [t0].[CreationDate], [t0].[PriceListName], [t0].[Currency], [t0].[IsActive], [t0].[LogoBlob]FROM [CompanyMain] AS [t0]");
        
        foreach (var c in Result)
        {
            Console.WriteLine(c);
        }
        return Result.ToList(); 
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900