I have a program to import data from an XML file into a SQL Server table. I am using the project by @Altafi Ansari here https://www.c-sharpcorner.com/article/xml-file-to-sql-database/. When i debug the program i get an "Incorrect syntax near 'TRANSACTION'" error as the flow starts creating the table . My observation are that the program can interpret the EXPORT_HEADER tag but the TRANSACTION tag is not being interpreted. I have attached my XML file here for clarity.
My XML is structured as below :
- <?xml version="1.0" encoding="utf-16"?>
- <EXPORT_HEADER xmlns="http://www.sir.com/SFI/Export/GL_Export/20051005" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sir.com/SFI/Export/GL_Export/20051005 GL_EXPORT.xsd" total_transactions="4616" total_accnts="2000">
- <TRANSACTION business_type_code="DIRECT" term="NB" />
- <TRANSACTION business_type_code="DIRECT" term="NB" />
- </EXPORT_HEADER>
However when i use the TRANSACTION tag section which contains the actual data i want to commit im getting the syntax error above:
- DataSet DS = new DataSet();
- DS.ReadXml(XMlFile);
- DataTable dt = DS.Tables[1];
- if (dt.Columns.Count == 0)
- dt.ReadXmlSchema(XMlFile);
- dt.ReadXml(XMlFile);
As a check i tried using EXPORT_HEADER section and the data in the header is successfully committed and table also created:
- DataSet DS = new DataSet();
- DS.ReadXml(XMlFile);
- DataTable dt = DS.Tables[0];
- if (dt.Columns.Count == 0)
- dt.ReadXmlSchema(XMlFile);
- dt.ReadXml(XMlFile);