如何从web.config文件读取连接字符串到类库中包含的公共类中?我试过了:WebConfigurationManagerConfigurationManager但是这些类在我的类库中无法识别。
3 回答
翻翻过去那场雪
TA贡献2065条经验 获得超13个赞
您需要添加一个引用System.Configuration,然后使用:
System.Configuration.ConfigurationManager.
ConnectionStrings["connectionStringName"].ConnectionString;
手掌心
TA贡献1942条经验 获得超3个赞
C#
// Add a using directive at the top of your code file
using System.Configuration;
// Within the code body set your variable
string cs = ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;
VB
' Add an Imports statement at the top of your code file
Imports System.Configuration
' Within the code body set your variable
Dim cs as String = ConfigurationManager.ConnectionStrings("connectionStringName").ConnectionString
- 3 回答
- 0 关注
- 635 浏览
添加回答
举报
0/150
提交
取消