XML, MS SQL, Bulkcopy, dataSet, C#

Posted on 2009-02-19
Last Modified: 2012-05-06
    <SpeakerName>Dr. John Rudy Jess</SpeakerName>
    <SpeakerLocation>Dallas, TX</SpeakerLocation>

If I have this XML structure, how can I parse this to write to dataset then to MS SQL
I have no problem with the root node but when it comes to the nested ones it cannot recoginize the field like for e.x. repID

Here's my code:

            DataSet reportData = new DataSet();
            reportData.ReadXml("C:\\XML\\" + tableName);

            SqlBulkCopy sbc = new SqlBulkCopy(sqlConn);
            sbc.DestinationTableName = "Locations";

            sbc.ColumnMappings.Add("RepID", "RepID");
            sbc.ColumnMappings.Add("PresentationKey", "PresentationKey");
            sbc.ColumnMappings.Add("VenueID", "VenueID");

Question by:jr_bautista
    LVL 12

    Expert Comment

    try changing

    sbc.DestinationTableName = "Locations";


    sbc.DestinationTableName = "Location";   // no s

    Author Comment

    "Locations" is the existing  MS SQL table name, it's not the fieldname - why would I change that?

    Author Comment

    Anybody can help me with this? Is this possible with DataSet  and Columnmappings? I appreciate if you could help me asap. Thanks!
    LVL 12

    Accepted Solution

    Try inserting this code
                foreach ( col In reportData.Tables[0].Columns )
                    { sbc.ColumnMappings.Add(col.ColumnName.Trim(), col.ColumnName.Trim()); }

    Open in new window


    Author Comment

    I think you have to write on Tables no as it corresponds to hierarchy in XML document. Tables[0] refers on the root, Tables[2] next one and so on....thanks!

    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

    Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 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

    17 Experts available now in Live!

    Get 1:1 Help Now