嗨,我有这个错误“对象引用未设置为对象的实例。”在我的字符串构造中。 这是什么意思? 谢谢你回答=)
private void BindGrid()
{
string constr = ConfigurationManager
.ConnectionStrings["conString"].ConnectionString; //Error here
sql = "select * from LogDetails";
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataTable t = new DataTable();
sda.Fill(t);
GridView1.DataSource = t;
GridView1.DataBind();
}
答案 0 :(得分:0)
您需要在web.config文件中添加连接字符串。
<connectionStrings>
<add name="conString" connectionString="Data Source=serverName;Initial Catalog=Northwind;Persist Security Info=True;UserID=userName;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>