c# quiz project

Viruzzz

New Member
Please help me with this error! Here ResultValue is an enumeration.Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0019: Operator '==' cannot be applied to operands of type 'string' and 'Answer.ResultValue'\[code\] Source Error: Line 38: Answer a = (Answer)al; Line 39: Line 40: if (a.Result == Answer.ResultValue.Correct) Line 41: correct=correct+1; Line 42: }\[/code\]=================================\[code\] using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class results : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { ArrayList al = (ArrayList)Session["AnswerList"]; if (al == null) { Response.Redirect("History.aspx"); } resultGrid.DataSource = al; resultGrid.DataBind(); // Save the results into the database. if (IsPostBack == false) { // Calculate score double questions = al.Count; double correct = 0.0; for (int i = 0; i < al.Count; i++) { Answer a = (Answer)al; if (a.Result == Answer.ResultValue.Correct) correct=correct+1; } double score = (correct / questions) * 100; SqlDataSource studentQuizDataSource = new SqlDataSource(); studentQuizDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); studentQuizDataSource.InsertCommand = "INSERT INTO UserQuiz ([QuizID], [DateTimeComplete], [Score], [UserName]) VALUES (@QuizID, @DateTimeComplete, @Score, @UserName)"; studentQuizDataSource.InsertParameters.Add("QuizID", Session["QuizID"].ToString()); studentQuizDataSource.InsertParameters.Add("Score", score.ToString()); studentQuizDataSource.InsertParameters.Add("UserName", User.Identity.Name); studentQuizDataSource.InsertParameters.Add("DateTimeComplete", DateTime.Now.ToString()); int rowsAffected = studentQuizDataSource.Insert(); if (rowsAffected == 0) { errorLabel.Text = "There was a problem saving your quiz results into our database. Therefore, the results from this quiz will not be displayed on the list on the main menu."; } }}protected void resultGrid_SelectedIndexChanged(object sender, EventArgs e){ SqlDataSource1.FilterExpression = "QuestionOrder=" + resultGrid.SelectedValue; }\[/code\] }code for Answer.cs\[code\] using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Answer : System.Web.UI.Page{ private string m_QuestionID; private string m_CorrectAnswer; private string m_UserAns; private string m_Result; public string QuestionID { get { return m_QuestionID; } set { m_QuestionID = value; } } public string CorrectAnswer { get { return m_CorrectAnswer; } set { m_CorrectAnswer = value; } } public string UserAns { get { return m_UserAns; } set { m_UserAns = value; } } public string Result { get { if (m_UserAns == m_CorrectAnswer) { return "Correct"; } else { return "Incorrect"; } } }public enum ResultValue{ Correct, Incorrect } }\[/code\]
 
Back
Top