如此配置
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Center" value="database=Center;server=01;uid=sa;pwd="";Max pool size =299;enlist=true;persist security info=true" />
</appSettings>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Center" value="database=Center;server=01;uid=sa;pwd="";Max pool size =299;enlist=true;persist security info=true" />
</appSettings>
</configuration>
解决方案 »
- 使用Microsoft.Office.Interop.Excel.dll这个com编写了处理excel的软件,再移植到其它电脑上怎么不可以使用?
- C#有没有类似delphi的package
- winform 中发布命令
- 求助:初学者的概念性问题.....
- winform窗体间的控制问题
- 菜鸟求助:关于MSMQ的问题!
- 能不能在主窗口中遍历应用程序中所有的窗体?
- 关于线程: 看看怎么解决
- 后台已经生成的excel文件,如何用浏览器发到客户端
- C# 中 大家常用的异常处理的好办法由哪些?
- checkbox????
- MemoryStream 类怎么存成文件?PictureBox怎么从一个指定路径提取文件?
XmlDocument doc = new XmlDocument();
doc.Load("yysms.exe.config");
XmlNode node = doc.DocumentElement.SelectSingleNode("appSettings");
node.SelectSingleNode("descendant::add[@key=Center]").Attributes[1].Value = ty;
doc.DocumentElement.SelectSingleNode("appSettings").InnerXml = node.InnerXml;
doc.Save("yysms.exe.config");
数据库联接的时候从xml文件中提取必要参数,
操作xml文件需要引用System.Xml;
那我该怎么读取其中的一个呢?
/// 修改配置文件(数据库连接字符串)
/// </summary>
/// <param name="connString"></param>
private void UpdateConfig( string databaseName )
{
Assembly Asm = Assembly.GetExecutingAssembly();
string fullPath = "";
fullPath = Asm.Location.Substring(0, (Asm.Location.LastIndexOf("\\") + 1) ) + "MakeAllowanceSheet.exe.config";
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(fullPath); XmlNodeList nodeList=xmlDoc.SelectSingleNode("/configuration/appSettings").ChildNodes;
foreach(XmlNode xn in nodeList)//遍历所有子节点
{
XmlElement xe=(XmlElement)xn; if( xe.GetAttribute("key").IndexOf("BC.MTARR.ConnectionString") != -1 )
{
xe.SetAttribute("value","server=" + databaseName + ";database=MTSIM;Connection Reset=FALSE;");
}
if( xe.GetAttribute("key").IndexOf("BC.MTARR.Server") != -1 )
{
xe.SetAttribute("value",databaseName );
}
}
xmlDoc.Save(fullPath);
}
app.config:<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="strUserName" value="ggggg" />
<add key="strPassWord" value="yyyyy" />
</appSettings></configuration>
cs里面:using System.Configuration;strUserName=ConfigurationSettings.AppSettings["strUserName"];
strPassWord=ConfigurationSettings.AppSettings["strPassWord"];