I have a making a grid view from code behind but the error occurs
My code is:
string str = ConfigurationManager.ConnectionStrings["SQLConn"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetData();
}
}
public void GetData()
{
SqlDataSource ds = new SqlDataSource();
ds.ConnectionString = str;
ds.SelectCommand = "SELECT * FROM mytableinfo";
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}
Error is for:
string str = ConfigurationManager.ConnectionStrings["SQLConn"].ConnectionString;
Object reference not set to an instance of an object.
Can anyone help me with this?