개체의 인스턴스로 설정되지 않았습니다 개체 :
What is a NullReferenceException in .NET?웹 양식을 참조 가능한 중복이
내가 필요로 한 페이지에 레이블의 무리가 업데이트 될 때 페이지로드. 나는 라벨의 ID가 "Label1"- "Label8"이라는 것을 알고 있지만 다음 스 니펫을 실행하면 "객체 참조가 객체의 인스턴스로 설정되지 않습니다."라는 메시지가 나타납니다. Label.Text 줄에 레이블을 찾을 수 없다고 가정합니다.
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++;
}
저는 아직 C#을 처음 사용하기 때문에 그다지 많이 시도하지 않았습니다.
거의 모든 NullReferenceException의 경우가 같습니다. 일부 힌트는 "[.NET의 NullReferenceException은 무엇입니까?] (http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)"를 참조하십시오. –