我想用一個數據庫與connectionstring
在應用程序配置文件連接,但總是收到此錯誤:未設置爲一個對象實例的ConnectionString:對象引用未設置爲一個對象實例
對象引用
在ConfigurationManger
的第一個代碼行中,我已經多次檢查過,但我認爲我沒有犯過錯誤。希望你能找到一些東西。
代碼
string con = ConfigurationManager.ConnectionStrings["dbConnect"].ConnectionString;
using (SqlConnection conn = new SqlConnection(con))
{
SqlDataAdapter adapter = new SqlDataAdapter("Select* From dsds m with (nolock) inner join asdas a with (nolock) on a.id = m.id where test....., conn);
ds = new DataTable(" ");
adapter.Fill(ds);
dataGridView1.DataSource = ds;
的App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="dbConnect"
connectionString="Data Source=test;Initial Catalog=as;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
的可能的複製[什麼是「不設置到對象的實例對象引用」呢?(http://stackoverflow.com/questions/779091/what-does- object-reference-not-set-to-an-instance-of-a-object-mean) – ViRuSTriNiTy