<appSettings>
<add key="cnstr" value="Data Source=192.168.1.4;Initial Catalog=test;User ID=sa;Password=sa"/>
</appSettings>
我想修改IP 查了个方法如下
public static void SetValue(string AppKey, string AppValue)
{
XmlDocument xDoc = new XmlDocument();
//获取可执行文件的路径和名称
xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config"); XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("//appSettings"); xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if (xElem1 != null)
xElem1.SetAttribute("value", AppValue);
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key", AppKey);
xElem2.SetAttribute("value", AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
}
private void btn_qux_Click(object sender, EventArgs e)
{ string appValue;
appValue = "Data Source=" + this.tb_sjkip.Text.Trim() + ";Initial Catalog=test;User ID=sa;Password=sa";
SetValue("cnstr", appValue);
MessageBox.Show("已修改!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}点了后提示已修改 但是IP没被修改
<add key="cnstr" value="Data Source=192.168.1.4;Initial Catalog=test;User ID=sa;Password=sa"/>
</appSettings>
我想修改IP 查了个方法如下
public static void SetValue(string AppKey, string AppValue)
{
XmlDocument xDoc = new XmlDocument();
//获取可执行文件的路径和名称
xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config"); XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("//appSettings"); xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if (xElem1 != null)
xElem1.SetAttribute("value", AppValue);
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key", AppKey);
xElem2.SetAttribute("value", AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
}
private void btn_qux_Click(object sender, EventArgs e)
{ string appValue;
appValue = "Data Source=" + this.tb_sjkip.Text.Trim() + ";Initial Catalog=test;User ID=sa;Password=sa";
SetValue("cnstr", appValue);
MessageBox.Show("已修改!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}点了后提示已修改 但是IP没被修改
再确认下是否有修改
再确认下是否有修改
RELEASE里面的没被修改 DEBUG中的被修改了, 修改后连接的数据库是不是指定机器上的啊?