Possible Duplicate:
What is a NullReferenceException in .NET?
I have a bunch of Labels on a single page that need to be updated when the page Loads. I know the labels' Ids are "Label1" - "Label8", however when i run the following snippet, I get "Object reference not set to an instance of an object." on the Label.Text line, so I'm assuming that the Label cannot be found.
int i = 1;
foreach (string sel in selArr)
{
string labelId = "Label" + i.ToString();
MySqlCommand cmd = new MySqlCommand(sel, conn);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Label label = (Label)FindControl(labelId);
label.Text = "( " + reader["c"] + " )";
}
reader.Close();
i++;
}
I haven't really tried much else because I'm still pretty new to C#.