0
我有一個SELECT COUNT查詢用於確定用戶是否已經被授予了成績,如果該特定用戶已經有一個成績,等級將變得不可見。然而,即使我給了那個學生一個等級,按鈕仍然會出現。當我在調試模式下啓動時,查詢的值爲空。下面是該方法的代碼:SELECT COUNT查詢不會產生我期待的結果
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;
}
太多不相關的代碼;你能否只發布必要的代碼 –
你真的應該考慮使用sql參數,而不是將值連接到你的SQL查詢中。 – juharr
@juharr你認爲使用這些連接值可能是問題的原因嗎?在 – Spiros