配置文件命令

添加参数配置文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="FactoryName" value="GDSFactory"/>
</appSettings>
</configuration>

调用:
添加using System.Configuration;引用
string factoryName = ConfigurationManager.AppSettings["FactoryName"];
进行添加


2.添加数据库链接文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="connstr" connectionString="server=.;database=SchoolIDB;uid=sa;pwd=123"/>
</connectionStrings>
</configuration>

调用
添加using System.Configuration;引用  //注意  要在当前层中添加configuration 并且在当前层中进行引用
private static readonly string connString = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;

SqlConnection conn = new SqlConnection(connString);

 

posted @ 2016-01-22 22:54  西瓜冰镇老板  阅读(297)  评论(0编辑  收藏  举报