convert type 'string' to 'System.Xml.XmlNode'

How can i convert the newconnectingstringvalue to xmlnode so i can replace in my web.config (xml) document.

error: Error 102 Cannot implicitly convert type 'string' to 'System.Xml.XmlNode'

C# code:

        public void button4_Click(object sender, EventArgs e)
        {
            string newConnectionStringValue = this.textBox13.Text;
            //label36.Text = newConnectionStringValue;

            XmlNode oldCd;
            XmlDocument docKB = new XmlDocument();
            docKB.Load("B:\\web.config");
            oldCd = docKB.SelectSingleNode("config/appSettings/add[@key='SQLdatabasename']/@value");

            XmlNode newCd;
            newCd = newConnectionStringValue;

            docKB.ReplaceChild(newCd, oldCd);


        }

[/code]

Why not simply do what you do 4 lines up?

First make an XmlDocument object and then call LoadXml(string) on that - and use that as your XmlNode

I got it to workin in memory:
how do i commit the changes to the file?

            string newConnectionStringValue = this.textBox13.Text;

            XmlNode oldNode;
            XmlDocument docKB = new XmlDocument();
            docKB.Load("B:\\web.config");
            oldNode = docKB.SelectSingleNode("configuration/appSettings/add[@key='sqlstring']/@value");
            oldNode.Value = newConnectionStringValue;

Quick search on Google found a code example:

xmlDoc.Save( Server.MapPath(“categories.xml”));

:slight_smile:

WoooHooo!!

I got it to work!

        public void button4_Click(object sender, EventArgs e)
        {
            string newConnectionStringValue = this.textBox13.Text;

            XmlNode oldNode;
            XmlDocument docKB = new XmlDocument();
            docKB.Load("B:\\web.config");
            oldNode = docKB.SelectSingleNode("configuration/appSettings/add[@key='sqlconnectionstring']/@value");
            oldNode.Value = newConnectionStringValue;
            docKB.Save(("B:\\web.config"));
        }