This is my code:
private string[] quizList;
public string[] getQuizList()
{
Databases.MoodleOCDataSetTableAdapters.QuizTableAdapter ta = new Databases.MoodleOCDataSetTableAdapters.QuizTableAdapter();
Databases.MoodleOCDataSet.QuizDataTable table = new Databases.MoodleOCDataSet.QuizDataTable();
ta.Fill(table);
System.Data.DataRow[] row = table.Select("id > 0");
for(int i = 0; i < row.Length; i++)
quizList[i] = row[i].ItemArray[2].ToString();
return quizList;
}
When I am debugging I can see the table is filled with data and row is also filled with data. But when it comes to the for loop, it always throwing null reference exception. What is the wrong with my code? Thanks!
Inside method initialize
quizListand then run loop.
Inside loop quizList is null and you are trying to access an index of it.
So your function should be like