Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8733869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:44:00+00:00 2026-06-13T09:44:00+00:00

I’m trying to populate a list ( lstContractor ) of a C# class (

  • 0

I’m trying to populate a list (lstContractor) of a C# class (contractor), containing fields and lists, from a DataSet returned from SQL. The DataSet returns multiple tables, linked by an id.

I’ve managed to get it all working except 1 field, which is the only field I need from the table it is in. When I’m trying to select it using LINQ, I’m getting System.Data.EnumerableRowCollection1[System.String]` instead of the contents of the field.

My Code looks like this:

    lstContractor = dsContractor.Tables[0].AsEnumerable().Select(contractor => new Contractor
    {
        intContractorId = contractor.Field<int>("ID"),
        strFirstName = contractor.Field<string>("FirstName"),
        strLastName = contractor.Field<string>("LastName"),
        strProfile = dsContractor.Tables[7].AsEnumerable().Where(profile => profile.Field<int>("ContractorId") == contractor.Field<int>("Id")).
            Select(profile => profile.Field<string>("ContractorProfile")).ToString(),
        // populate addresses
        Address = dsContractor.Tables[6].AsEnumerable().Where(address => address.Field<int>("ContractorId") == contractor.Field<int>("Id")).
                Select(address => new Address
                {
                    intId = address.Field<int>("ContractorId"),
                    strAddressLine1 = address.Field<string>("AddressLine1"),
                    strAddressLine2 = address.Field<string>("AddressLine2"),
                    strAddressLine3 = address.Field<string>("AddressLine3"),
                    strAddressLine4 = address.Field<string>("AddressLine4"),
                    strAddressLine5 = address.Field<string>("AddressLine5"),
                    strPostCode = address.Field<string>("PostCode")
                }).ToList<Address>(),

        // populate industries
        Industry = dsContractor.Tables[1].AsEnumerable().Where(Industry => Industry.Field<int>("ContractorId") == contractor.Field<int>("Id")).
            Select(target => new Industry
            {
                intId = target.Field<int>("ContractorId"),
                strIndustryName = target.Field<string>("IndustryName")
            }).ToList<Industry>(),

        // populate key skills
        KeySkill = dsContractor.Tables[2].AsEnumerable().Where(KeySkill => KeySkill.Field<int>("ContractorId") == contractor.Field<int>("Id")).
            Select(target => new KeySkill
            {
                intId = target.Field<int>("ContractorId"),
                strKeySkillName = target.Field<string>("KeySkillName")
            }).ToList<KeySkill>(),

        // populate email addresses
        EmailAddress = dsContractor.Tables[3].AsEnumerable().Where(EmailAddress => EmailAddress.Field<int>("ContractorId") == contractor.Field<int>("Id")).
            Select(target => new EmailAddress
            {
                intId = target.Field<int>("ContractorId"),
                strEmailAddress = target.Field<string>("EmailAddress"),
                strEmailType = target.Field<string>("EmailType")
            }).ToList<EmailAddress>(),

        // populate phone numbers
        PhoneNumber = dsContractor.Tables[4].AsEnumerable().Where(PhoneNumber => PhoneNumber.Field<int>("ContractorId") == contractor.Field<int>("Id")).
            Select(target => new PhoneNumber
            {
                intId = target.Field<int>("ContractorId"),
                strPhoneNumberType = target.Field<string>("PhoneType"),
                strPhoneNumber = target.Field<string>("PhoneNumber")
            }).ToList<PhoneNumber>(),

        Geography = dsContractor.Tables[5].AsEnumerable().Where(PhoneNumber => PhoneNumber.Field<int>("ContractorId") == contractor.Field<int>("Id")).
                Select(target => new Geography
                {
                    intId = target.Field<int>("ContractorId"),
                    strGeography = target.Field<string>("GeographyName")
                }).ToList<Geography>(),


    }).ToList<Contractor>();

the class looks like this:

    public int intContractorId;
public string strFirstName;
public string strMiddleName;
public string strLastName;
public string strDescription; 
public DateTime dtDOB;
public string strGender;
public string strProfile;
public int intIsFullTime;
public int intWorkMonday;
public int intWorkTuesday;
public int intWorkWednesday;
public int intWorkThursday;
public int intWorkFriday;
public int intWorkSaturday;
public int intWorkSunday;
public DateTime dtAvailableFrom;
public int intActive;
public decimal dcSubscrptionCost;
public DateTime dtRenewalDate;
public List<Address> Address;
public List<EmailAddress> EmailAddress;
public List<PhoneNumber> PhoneNumber;
public List<KeySkill> KeySkill;
public List<Geography> Geography;
public List<Industry> Industry;
public List<SubIndustry> SubIndustry;

The field in question is strProfile, but I can’t for the life of me figure out why I’m getting the contents that I am, instead of the string the the field contains.

I’ve checked in debug mode, and the correct data is in the DataSet.

Please let me know if I’ve missed anything.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:44:02+00:00Added an answer on June 13, 2026 at 9:44 am

    This part:

    ...Select(profile => profile.Field<string>("ContractorProfile")).ToString()
    

    Linq’s Select() returns an IEnumerable, so ToString() is just going to try to tell you that it’s an IEnumerable. If you want the first item from the returned collection, use First() or FirstOrDefault():

    ...Select(profile => profile.Field<string>("ContractorProfile")).First().ToString()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.