XML, MS SQL, Bulkcopy, dataSet, C#

    <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");

Who is Participating?
williamcampbellConnect With a Mentor Commented:
Try inserting this code
            foreach ( col In reportData.Tables[0].Columns )
                { sbc.ColumnMappings.Add(col.ColumnName.Trim(), col.ColumnName.Trim()); }

Open in new window

try changing

sbc.DestinationTableName = "Locations";


sbc.DestinationTableName = "Location";   // no s
jr_bautistaAuthor Commented:
"Locations" is the existing  MS SQL table name, it's not the fieldname - why would I change that?
jr_bautistaAuthor Commented:
Anybody can help me with this? Is this possible with DataSet  and Columnmappings? I appreciate if you could help me asap. Thanks!
jr_bautistaAuthor Commented:
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!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.