<appSettings>
<add key=”Data Source” value=”.”/>
<add key=”uid” value=”sa”/>
<add key=”pwd” value=”123″/>
<add key=”database” value=”MaterialSystem_DB”/>
</appSettings>
在配置文件中是这样的怎么样才能读取变成一句连接字符串呢?在程序中怎么用这些<add>标签!急在线等谢谢各位高手了
<add key=”Data Source” value=”.”/>
<add key=”uid” value=”sa”/>
<add key=”pwd” value=”123″/>
<add key=”database” value=”MaterialSystem_DB”/>
</appSettings>
在配置文件中是这样的怎么样才能读取变成一句连接字符串呢?在程序中怎么用这些<add>标签!急在线等谢谢各位高手了
解决方案
10
string dc = System.Configuration.ConfigurationManager.AppSettings[“Data Source”];
string id = System.Configuration.ConfigurationManager.AppSettings[“uid”];
…
string id = System.Configuration.ConfigurationManager.AppSettings[“uid”];
…
10
Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //根据Key读取<add>元素的Value string name = config.AppSettings.Settings["uid"].Value;
60
string.Format("Data Source={0},uid={1},pwd={2}" ,ConfigurationManager.AppSettings["Data Source"] ,ConfigurationManager.AppSettings["uid] ,ConfigurationManager.AppSettings["pwd])