好久没有写博客了,不能就这么丢弃,呵呵.
随便找点东西写写吧,今天工作时突然忘记了怎么使用web.config文件中的connectionstring.
相信有过asp.net经验的朋友都会用配置文件来存储数据库信息,
我来写一下web.config中的连接字符串的赋值.
<connectionStrings>
<add name="JKXTConnectionString" connectionString="Data Source=CHF;Initial Catalog=JKXT;User ID=sa" providerName="System.Data.SqlClient" />
<add name="JGXTConnectionString" connectionString="Data Source=CHF;Initial Catalog=JGXT;User ID=sa" providerName="System.Data.SqlClient" />
</connectionStrings>
获取的办法是:
ConfigurationManager.ConnectionStrings["JGXTConnectionString"].ConnectionString;
或者这么写web.config
<appSettings>
<add key="connectionstring" value="Data Source=CHF;Initial Catalog=JGXT;User ID=sa"/>
</appSettings>
获取办法是:
ConfigurationSettings.AppSettings["JGXTConnectionString"];
呵呵,记住了啊.要引用using System.Configuration;