I have no idea what had I coded wrong in my project, please help. Basically, I was creating a function for the program to check if a certain string is in a string. I have connected to Access Database, return a string such as "asdf,dfgh,ghjk" then the function will check if "dfgh" is in it. Here is my code:
private void RefreshAppliedLessonsTable()
{
Table_AppliedLessons.Rows.Clear();
for (int i = 0; i < Table_Lessons.Rows.Count; i++)
{
string CursorLessonName = Table_Lessons.Rows[i].Cells[0].Value.ToString();
string LessonID = functions.ReturnLessonID(CursorLessonName);
string AppliedStudentsPerLesson = functions.ReturnAppliedStudents(LessonID);
if (AppliedStudentsPerLesson.IndexOf(LTB_StudentID.Text) != -1)
{
string LessonName = string.Empty;
string LessonCourse = string.Empty;
string LessonTeacher = string.Empty;
string Level = string.Empty;
string Time = string.Empty;
string QuotaLeft = string.Empty;
string Price = string.Empty;
LessonName = Table_Lessons.Rows[i].Cells[0].Value.ToString();
LessonCourse = Table_Lessons.Rows[i].Cells[1].Value.ToString();
LessonTeacher = Table_Lessons.Rows[i].Cells[2].Value.ToString();
Level = Table_Lessons.Rows[i].Cells[3].Value.ToString();
Time = Table_Lessons.Rows[i].Cells[4].Value.ToString();
QuotaLeft = Table_Lessons.Rows[i].Cells[5].Value.ToString();
Price = Table_Lessons.Rows[i].Cells[6].Value.ToString();
Table_AppliedLessons.Rows.Add(new object[] { LessonName, LessonCourse, LessonTeacher, Level, Time, QuotaLeft, Price });
}
}
Then I'll execute this code when the form loads. However the datagridview table "Table_AppliedLessons" will never be populated. It is being confirmed that the database has the string in it. Anyone can help?
Answer to this problem:
As @SchlaWiener suggested I might have excluded some bugs in my program by default. After using the CTRL + ALT + E
and check Common Language Runtime exceptions -> thrown
checkbox. I saw that there is an error in the functions.ReturnLessonID(CursorLessonName);
Where I've supplied the wrong parameters to the function, causing it to return a string.Empty;
thus it cannot be added to the table. Thank you @SchlaWiener once again for the suggestion.
Finally, I would suggest having this modification of settings in visual studio such that you would not miss a "Hidden bug".
I'm sorry that I have to post this in my question since I cannot answer my own question due to my points.