{"id":5141,"date":"2014-03-30T19:12:04","date_gmt":"2014-03-30T19:12:04","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/c-console-app-sqlbulkcopy-and-quickly-entering-xml-into-a-sql-server-db-collection-of-common-programming-errors\/"},"modified":"2014-03-30T19:12:04","modified_gmt":"2014-03-30T19:12:04","slug":"c-console-app-sqlbulkcopy-and-quickly-entering-xml-into-a-sql-server-db-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/c-console-app-sqlbulkcopy-and-quickly-entering-xml-into-a-sql-server-db-collection-of-common-programming-errors\/","title":{"rendered":"C# console app. SQLBulkCopy and quickly entering XML into a SQL Server DB-Collection of common programming errors"},"content":{"rendered":"<p>C# with .net 2.0 with a SQL server 2005 DB backend.<\/p>\n<p>I&#8217;ve a bunch of XML files which contain data along the lines of the following, the structure varies a little but is more or less as follows:<\/p>\n<pre><code>\n  \n    All current tanks \n    Tank is close to capacity \n     \n     \n     \n  \n\n<\/code><\/pre>\n<p>I have a single DB table that has all the above fields ready to be filled.<\/p>\n<p>When I use the following method of reading the data from the XML file:<\/p>\n<pre><code>DataSet reportData = new DataSet();\nreportData.ReadXml(\"..\/File.xml\");\n<\/code><\/pre>\n<p>It successfully populates the Dataset but with multiple tables. So when I come to use SQLBulkCopy I can either save just one table this way:<\/p>\n<pre><code>sbc.WriteToServer(reportData.Tables[0]);\n<\/code><\/pre>\n<p>Or if I loop through all the tables in the Dataset adding them it adds a new row in the Database, when in actuality they&#8217;re all to be stored in the one row.<\/p>\n<p>Then of course there&#8217;s also the issue of columnmappings, I&#8217;m thinking that maybe SQLBulkCopy is the wrong way of doing this.<\/p>\n<p>What I need to do is find a quick way of getting the data from that XML file into the Database under the relevant columns in the DB.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C# with .net 2.0 with a SQL server 2005 DB backend. I&#8217;ve a bunch of XML files which contain data along the lines of the following, the structure varies a little but is more or less as follows: All current tanks Tank is close to capacity I have a single DB table that has all [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5141","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5141"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5141\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}