I need help to get my XML Elements using XElement into SQL Server. When I run the code the MessageBox.Show(element.ToString(), "element.value");
is displaying the <FIELD fieldName="ID">1234567</FIELD>
and <FIELD fieldName="DateTime">05/02/2018 09:00:28</FIELD>
in the MessageBox correctly. Can I now use this to upload to my tblMain in SQL Server?
Basically it is a string saved as input from a .msg body in outlook. This msg body has all the text as an XML in the body as plain text format.
I load the string input as xml document into XmlDocument.
With XElement I then parse this input as xml. I create a variable xitems with the xml Descendants as ("FIELD") where I run a foreach loop as variable element in the xitems. The output is now displayed in the MessageBox.
Please, what I am looking for is detailed help in how to get this into SQL Server to a table called tblMain for simplicity it has two columns ID and DateTime??
The code:
for (int i = 1; i < publicFolder.Items.Count; i++)
{
item = (PostItem)publicFolder.Items[i];
if (item != null)
{
//MessageBox.Show(item.Body, "Body");
//save the msg body into the string
string input = item.Body;
//load the string input as xml document
XmlDocument doc = new XmlDocument();
doc.LoadXml(input);
XElement xml = XElement.Parse(input);
var xitems = xml.Descendants("FIELD");
foreach (var element in xitems)
{
MessageBox.Show(element.ToString(), "element.value");
}
////Create new instance of SQL Connection
//SqlConnection conn = new SqlConnection();
The xml file is :https://imgur.com/a/epCLd22