我有一个SELECT COUNT查询,用于确定用户是否已获得成绩,如果该特定用户已有成绩,则提交成绩的按钮将变为不可见。但是,即使我已经给了该学生一个成绩,按钮仍然会出现。当我在调试模式下启动时,查询的值为null。以下是方法中的代码:
String connectionString = WebConfigurationManager.ConnectionStrings["UniString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
String modOnpwayModID = "SELECT id FROM module_on_pathway WHERE module_id = '" + modDropDown.SelectedValue + "'";
SqlCommand modOnpwayModIDQuerycmd = new SqlCommand(modOnpwayModID, myConnection);
Int32 modOnpwayModIDResult = Convert.ToInt32(modOnpwayModIDQuerycmd.ExecuteScalar().ToString());
Label lb = (Label)e.Item.FindControl("user_idLabel");
String userIDLabel = lb.Text.ToString();
Int32 usrIDVal = Convert.ToInt32(userIDLabel);
String gradeSelectionQuery = "SELECT COUNT(student_module_grade.grade) FROM student_module_grade INNER JOIN classlist ON student_module_grade.classlist_id = classlist.classlist_id INNER JOIN student_assignment_grade ON student_module_grade.classlist_id = student_assignment_grade.classlist_id INNER JOIN assignments ON student_assignment_grade.assignment_id = assignments.assignment_id WHERE student_module_grade.module_on_pathway_id ='" + modOnpwayModIDResult + "'AND classlist.user_id = '" + userIDLabel + "'";
SqlCommand gradeSelectionQuerycmd = new SqlCommand(gradeSelectionQuery, myConnection);
Int32 gradeCount = Convert.ToInt32(gradeSelectionQuerycmd.ExecuteScalar().ToString());
//See if a final score has been given already- can then be changed by the admin if it needs to be changed
if (gradeCount == 0)
{
submitmodMark1st.Visible = true;
//All elements for grade submission made invisible- admin will be unable to change the grade
//TB.Visible = false;
//changedFlagVal.Text = "The grade for this module has already been changed for the selected student";
//changedFlagVal.Visible = true;
//changedFlagVal.ForeColor = System.Drawing.Color.Red;
}
else
{
submitmodMark1st.Visible = false;
}
String repeatGradeSelectionQuery = "SELECT COUNT(student_module_repeat_grades.grade) FROM student_module_repeat_grades INNER JOIN classlist ON student_module_repeat_grades.classlist_id = classlist.classlist_id INNER JOIN student_assignment_grade ON student_module_repeat_grades.classlist_id = student_assignment_grade.classlist_id INNER JOIN assignments ON student_assignment_grade.assignment_id = assignments.assignment_id WHERE student_module_repeat_grades.module_on_pathway_id ='" + modOnpwayModIDResult + "'AND classlist.user_id = '" + userIDLabel + "'";
SqlCommand repeatGradeSelectionQuerycmd = new SqlCommand(repeatGradeSelectionQuery, myConnection);
Int32 repeatGradeCount = Convert.ToInt32(repeatGradeSelectionQuerycmd.ExecuteScalar().ToString());
if (repeatGradeCount == 0)
{
submitmodMark1st.Visible = true;
}
else
{
//All elements for grade submission made invisible- admin will be unable to change the grade
//TB.Visible = false;
changedFlagVal.Text = "The grade for this module has already been changed for the selected student";
changedFlagVal.Visible = true;
changedFlagVal.ForeColor = System.Drawing.Color.Red;
submitmodMark1st.Visible = false;
}