高人在哪里?

jhdxhj 2009-05-21 06:27:48
如何修改下面的config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="OTMS.Properties.Settings.OTMSConnectionString" connectionString="Data Source=192.168.1.120;Initial Catalog=OTMS;Persist Security Info=True;User ID=sa;Password=123" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
如何把connectionString="Data Source=192.168.1.120;Initial Catalog=OTMS;Persist Security Info=True;User ID=sa;Password=123"
改为
connectionString="Data Source=192.168.1.121;Initial Catalog=OTMS;Persist Security Info=True;User ID=sa;Password=123" 并且保存下来?
这个配置文件的名字叫App1.config,请高人指点
...全文
127 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
sd6733531 2009-05-21
  • 打赏
  • 举报
回复
System.Configuration.Configuration config=System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
config.GetSection("configuration/connectionStrings");
//....
wuyq11 2009-05-21
  • 打赏
  • 举报
回复
private void SetValue()
{
string xmlfile = Application.StartupPath+ "app1.config";
DataSet ds = new DataSet();
ds.ReadXml(xmlfile);
ds.Tables["add"].PrimaryKey = new DataColumn[] { ds.Tables["add"].Columns["name"] };
ds.Tables["add"].Rows.Find("OTMS.Properties.Settings.OTMSConnectionString")["connectionString"] = "";
ds.WriteXml(xmlfile);
}
参考
W422080367 2009-05-21
  • 打赏
  • 举报
回复
Configuration.ConfigurationManager类里有对app.Config文件进行操作的方法
jhdxhj 2009-05-21
  • 打赏
  • 举报
回复
我是要在程序中修改这东西,不知道如何写
兔儿爷 2009-05-21
  • 打赏
  • 举报
回复
没说清楚啊,是手动修改,还是程序中动态修改?

参考 http://www.ideaext.com/read.php/298.htm
love_幸运儿 2009-05-21
  • 打赏
  • 举报
回复
查看XML相关内容
jhdxhj 2009-05-21
  • 打赏
  • 举报
回复
我要修改这个这个东西
cstester 2009-05-21
  • 打赏
  • 举报
回复
你的意思是要动态写这个config 还是?

一个程序 只能有一个config文件啊!!!

动态写你可以使用XmlDocument XmlElement类写,
或者用FileStream 文件流写, 都可以.
happyer_longlong 2009-05-21
  • 打赏
  • 举报
回复
啥意思 要干嘛?
SK_Aqi 2009-05-21
  • 打赏
  • 举报
回复
就是xml的解析啊,查看下xml解析的相关东西.
SK_Aqi 2009-05-21
  • 打赏
  • 举报
回复
高人沙发!!!

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧