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

  • Home
  • SEARCH
  • 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 977725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:56:50+00:00 2026-05-16T03:56:50+00:00

When looping through elements it thinks the child node is a table, when it

  • 0

When looping through elements it thinks the child node is a table, when it should just be a column. I have most of the code working well, until I the code gets to this part: (all of my code is at the bottom)

new XElement("TBL_Magic_TripCountries", lstCountry.Items
                                .Cast<ListItem>()
                                .Where(i=> i.Selected)
                              .Select(x => new XElement("CountryCode", x.Value))
                    ),

I am receiving a Cannot access destination table ‘CountryCode’. I have no idea why this thinks this is a table if its nested within another node. I am trying to set CountryCode from TBL_Magic_TripCountries, but its not working as I thought. Any help?

XDocument xmlDoc = new XDocument(
            new XDeclaration("1.0", "utf-8", "yes"),
            new XComment("Created: " + DateTime.Now.ToString()),
            new XElement("Trips",
                new XElement("TBL_TripDetails",
                    new XElement("DepartureDate", txtDepartureDate.Text),
                    new XElement("ReturnDate", txtReturnDate.Text),
                    new XElement("TripRecommendation", tripRecommend),
                    new XElement("TripRecommendationComment", txtTripRecommendComment.Text),
                    new XElement("TripFavouriteThing", txtLikeMostComment.Text)
                  ),
                  new XElement("TBL_Magic_TripCountries", lstCountry.Items
                                .Cast<ListItem>()
                                .Where(i=> i.Selected)
                              .Select(x => new XElement("CountryCode", x.Value))
                    ),
                     new XElement("TBL_Cities", lstCities.Items
                                .Cast<ListItem>()
                                .Select(x => new XElement("City", x.Text))),)

               ));

…

DataSet ds = new DataSet();
            ds.ReadXml(xDoc.CreateReader());
            string StrConn = ConfigurationManager.ConnectionStrings["myConn"].ConnectionString;
            SqlConnection cnn = new SqlConnection(StrConn);

            SqlBulkCopy blkcopy = new SqlBulkCopy(cnn);
            cnn.Open();
            foreach (DataTable dt in ds.Tables)
            {
                BulkCopyTable(dt, blkcopy);
            }

EDIT my XML looks like this before I start putting it in the dataset

<!--Created: 8/4/2010 8:28:10 AM-->
<Trips>
  <TBL_TripDetails>
    <DepartureDate>2/2/2010</DepartureDate>
    <ReturnDate>2/2/2010</ReturnDate>
    <TripTypeA>1</TripTypeA>
    <TripTypeB>2</TripTypeB>
    <PurposeOfTrip>vacation</PurposeOfTrip>
    <RegionID>2</RegionID>
    <OverallRating>0</OverallRating>
    <SupplierID>3</SupplierID>
    <SupplierComment>great supplier</SupplierComment>
    <FoodRating>0</FoodRating>
    <CulinaryComments></CulinaryComments>
    <RecommendRestaurant>false</RecommendRestaurant>
    <AttractionDisappoint>false</AttractionDisappoint>
    <TripRecommendation>false</TripRecommendation>
  </TBL_TripDetails>
  <TBL_Magic_TripCountries>
    <CountryCode>USA</CountryCode>
    <CountryCode>CND</CountryCode>
  </TBL_Magic_TripCountries>
  <TBL_Cities>
    <City>New York</City>
    <City>Ottawa</City>
    <City>Las Vegas</City>
  </TBL_Cities>
  <TBL_Magic_TripTransportation>
    <TransportType>3</TransportType>
    <TransportType>4</TransportType>
  </TBL_Magic_TripTransportation>
</Trips>
  • 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-05-16T03:56:51+00:00Added an answer on May 16, 2026 at 3:56 am

    I can’t be certain this is the cause, but

    lstCountry.Items 
        .Cast<ListItem>() 
        .Where(i=> i.Selected) 
        .Select(x => new XElement("CountryCode", x.Value))
    

    retruns an IEnumerable<XElement> and would be interpreted by the dataset as an element with multiplicity of 0..∞. Datasets will translate that element as a table internally because that’s how datasets handle nested relationships. I’m not sure if you’d end up with two tables (“TBL_Magic_TripCountries” associated with your main table and then “CountryCode” associated with it) or a single table “TBL_Magic_TripCountries” with CountryCode as the only column. It’s been too long since I dealt with auto-schema-generated datasets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 516k
  • Answers 516k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, use enums (not defines) instead of true/false. That way,… May 16, 2026 at 6:48 pm
  • Editorial Team
    Editorial Team added an answer This is a typecast, used to tell the compiler that… May 16, 2026 at 6:48 pm
  • Editorial Team
    Editorial Team added an answer To toggle play/pause you will need to record the position… May 16, 2026 at 6:48 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Is there a way to programatically go through a window's child elements to find
Does anybody know how one would go about looping through all the elements in
I can easily identify running processes by looping through the WMI Win32_Process elements. Is
I have a loop that iterates through elements in a list. I am required
I am trying to loop through some elements in a form (radios, text boxes,
My code does not pull the proper link for the item. Instead it's getting
Does jQuery - or one of it's plugins - have equivalent functionality to the
I have a hash of hashes, like so: %hash = ( a => {
I've got a page of elements, each of which, depending on user interaction, may
I have a long cities list. I was looking for an equivalent to sectionIndexTitlesForTableView

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.