0

Hi Guys..

Hoping you can help here.. I'm dabbling with Linq as I'm wanting to pass a Node Value from the XML file into the Connection String.

Currently my Code seems to be working and holding the Value in the System.(Code Below:)(Screenshot attached also)

         XDocument testXML = XDocument.Load("C:\\twDB.xml");
            var DataBases = from DataBase in testXML.Descendants("DataBase")
            select new
            {
              Connection = DataBase.Element("Connection").Value.ToString()
            };

I placed a textbox1 onto my form just to make sure I could pass the value but i'm not able too?

Any help on this would be great.

Regards
Mark.

Attachments Capture11.PNG 53.36 KB
2
Contributors
1
Reply
9
Views
4 Years
Discussion Span
Last Post by Ketsuekiame
0

Have you tried using XPath?
It will allow you to "query" XML.

For example;

XPathNavigator rootNav = testXML.CreateNavigator();
foreach(XPathNavigator databaseNav in rootNav.Select("/DataBase/Connection"))
    Connection.Add(databaseNav.Value);

or if you really want to use LINQ

XPathNavigator rootNav = testXML.CreateNavigator();
var connection = from nodeSelector in rootNav.Select("/DataBase/Connection")
                 select nodeSelector.Value;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.