在vs 2005中怎么取得app.config中connectionStrings的值??
好像的web,config不一样呀
ConfigurationManager.ConnectionStrings["newsConnectionString"].ConnectionString对app.config怎么有错误而对web.config就是对的???
不明白
好像的web,config不一样呀
ConfigurationManager.ConnectionStrings["newsConnectionString"].ConnectionString对app.config怎么有错误而对web.config就是对的???
不明白
解决方案 »
- C# 指针问题
- 控件的深度
- ADO.NET关于存储过程返回参数接收问题??
- C# ComboBox边框颜色和borderstyle
- Nhibernate 问题 急!在线等!
- 多线程中的new问题
- 一个关于的DataGird的难题,有兴趣的高手进来看一下
- 关于子弹的问题
- (WinForm)中的DataGrid可以实现标题和内容不同的对齐方式吗?
- Winform + webservices+db2 问题:服务器无法处理请求,访问器验证被推迟,并在该方法返回数据时已执行,绑定对于此列或参数无效
- 微软高手接招,打印预览象死机一样!!!!!
- web form与win form中,请问在insert插入字符串sql语句中,怎么插入 '单引号,不出错?有什么简便的方法吗?
http://www.ham.cn/user2/zhshy202/archives/2006/121417.html
string connStr=System.Configuration.ConfigurationManager.ConnectionStrings["newsConnectionString"].ToString();
要把他转成字符串形式
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="Test3" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<Test3>
<add key="Hello" value="World" />
</Test3>
</configuration>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
调用部分的代码:
(需要
using System.Configuration; // 引用前需要添加此dll的引用
using System.Collections.Specialized;
)
—————————————————————————————————
//访问配置节Test3
NameValueCollection nc = (NameValueCollection)ConfigurationSettings.GetConfig("Test3");
MessageBox.Show(nc.AllKeys[0].ToString() + " " + nc["Hello"]); //输出Hello World
解决方案资源管理器下有引用文件夹,右击引用。选择添加引用System.Configuration
马上结贴
ConnectionString是你在APP里面定义的比如
<appSettings>
<add key="ConnectionString" value="database=books;server=(local);min pool size=1;max pool size=8;packet size=3072;Integrated Security=SSPI"/></appSettings>
给分把西西
string b = a.ConnectionString;
MessageBox.Show(b);
connection = new OracleConnection(b);
//connection = new OracleConnection("Data Source=smdb_218.193.155.252;Persist Security Info=True;User ID=semantic;Password=shq888;Unicode=True");
connection.Open();
龙兄说的对,但是楼主还是不结贴,我们鄙视一下先