我不知道我在我的项目中写错了什么,请帮忙。基本上,我正在为程序创建一个函数来检查某个字符串是否在字符串中。我已连接到 Access 数据库,返回一个字符串,例如“asdf,dfgh,ghjk”,然后该函数将检查“dfgh”是否在其中。这是我的代码:
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 });
}
}
然后我将在表单加载时执行此代码。然而,datagridview 表“Table_AppliedLessons”将永远不会被填充。正在确认数据库中有字符串。任何人都可以帮忙吗?
Answer to this problem:
正如@SchlaWiener 建议的那样,默认情况下我可能已经排除了我的程序中的一些错误。使用CTRL + ALT + E
并选中Common Language Runtime exceptions -> thrown
复选框后。我看到在functions.ReturnLessonID(CursorLessonName);
Where I've provide wrong parameters to the function 中存在错误,导致它返回 astring.Empty;
因此无法将其添加到表中。再次感谢@SchlaWiener 的建议。
最后,我建议在 Visual Studio 中对设置进行这种修改,这样您就不会错过“隐藏的错误”。
I'm sorry that I have to post this in my question since I cannot answer my own question due to my points.