NullReferenceExeception
获取 connectionString 时, app.config
正在生成
连接字符串我创建为:
<connectionStrings>
<add name="Connect" connectionString="server=localhost;port=3306;user id=customer;password=hassaan09;database=customer" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
但是检索连接字符串异常正在生成我使用的:
public List<customer> LoadGridView()
{
List<customer> lstCustomer = new List<customer>();
try
{
string connectionString = ConfigurationManager.ConnectionStrings["Connect"].ConnectionString; //Here exception is generating
// string connectionString = "server=localhost;port=3306;user id=customer;password=hassaan09;database=customer"; //if i directly provide connectionstring it will work fine
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
using (MySqlCommand cmd = new MySqlCommand("Select customerid,name,email,age from customerinfo", conn))
{
conn.Open();
}
}
}
catch(Exception ex)
{ MessageBox.Show(ex.ToString()); }
return lstCustomer;
}