现在的位置: 首页 > 综合 > 正文

WinForm(C#) 引用app.config文件中的数据库

2013年10月03日 ⁄ 综合 ⁄ 共 417字 ⁄ 字号 评论关闭

app.config   中一部份代码

<configuration>

<appSettings>    //注意要加上这个,否责会报错,“什么为能初始化之类”

<add key="ConnSqlStr" value="数据库链接字段"/>  

                                                     //  要用像 web开发似的(web.config)中还要加providerName这个数据库提供者,否责一样报错

</appSettings>

</configuration>

 

 

引用:

            string conn = configuration.configurationSettings.AppSettings["ConnSqlStr"].tostring();

 sqlconnection con = new sqlconnection(conn);

 

 

 

初学者,自己的写法,如有不对,多多包涵

抱歉!评论已关闭.