在winform下取app.config文件中的值
app.config文件的内容如下:
<?xml version= "1.0 " encoding= "utf-8 " ?>
<configuration>
<ConnectionStrings>
<add name= "OracleConnectionString "
connectionString= "Data Source=db;User ID=system;Unicode=True "
providerName= "System.Data.OracleClient " />
</ConnectionStrings>
</configuration>
form.cs代码如下:
richTextBox1.Text = System.Configuration.ConfigurationManager.ConnectionStrings[ "OracleConnectionString "].ToString();
结果提示为,
未将对象引用设置到对象的实例 我原来只用过web 中的web.config,是可以的,请问为什么取不到值?
------解决方案-------------------- <?xml version= "1.0 " encoding= "utf-8 " ?>
<configuration>
<connectionStrings>
<add name= "test " connectionString= "Data Source=test;Initial Catalog=SIS;Persist Security Info=True;User ID=admin;Password=admin "
providerName= "System.Data.SqlClient " />
</connectionStrings>
</configuration>
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text =
System.Configuration.ConfigurationManager.ConnectionStrings[ "test "].ToString();
}