Thursday, 8 May 2014

calculate marks and select rows from storedprocedure

No comments
Query

select distinct Stu_exam.Stu_id,Stu_exam.Exam_id,Stu_exam.Question_no,Stu_exam.Answer,Questions.Answer_text from Stu_exam,Questions where Stu_exam.Stu_id=@Stu_id and Stu_exam.Exam_id=@Exam_id and Stu_exam.Question_no=Questions.Question_no and Stu_exam.Exam_id=Questions.Exam_id


.cs


protected void btnmarks_Click(object sender, EventArgs e)
    {
        store_choice();
        int Correct = 0, Incorrect = 0, Total = 0;
        dl.stu_id = Convert.ToInt16(Session["Stu_id"]);
        dl.exam_id = Convert.ToInt16(lblid.Text);
        DataTable dt = new DataTable();
        dt = bl.calculate_marks(dl);
        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i][3].ToString() == dt.Rows[i][4].ToString())
                {
                    Correct = Correct + 2;
                }
                else if (dt.Rows[i][3].ToString() != "Not Attempt")
                {
                    Incorrect = Incorrect + 0;
                }
            }
        }
        Total = Correct - Incorrect;
        dl.exam_name = lblname.Text;
        dl.exam_marks = Total;
        bl.insert_marks(dl);
        Response.Redirect("exam_marks.aspx");

    }