Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: , +
C#
protected void Timer1_Tick(object sender, System.EventArgs e)
	{
		DateTime mydate2 = DateTime.Now;
		DateTime mydate3 = default(DateTime);

		try {
            mydate3 = (mydate - mydate2).ToString();
			this.Label5.Text = "Time Left: " + mydate3.ToShortTimeString();
		} catch (Exception ex) {
			this.Label5.Text = "Error Setting up the Timer. Contact Admin";
		}

        
		if (mydate3.ToShortTimeString() == "00:00:00") {
			int marks = 0;
			Session["Answered"]=dt ;

			foreach (object x_loopVariable in dt.Rows) {
				 x=x_loopVariable ;
				if (x("Selected") + 1 == x("correct")) {
					marks += 1;

				}
			}


I got errors in this code:
C#
mydate3 = (mydate - mydate2).ToString();

C#
foreach (object x_loopVariable in dt.Rows) {
				 x=x_loopVariable ;
				if (x("Selected") + 1 == x("correct")) {
					marks += 1;
Posted
Updated 5-Nov-11 3:08am
v2
Comments
Philippe Mori 5-Nov-11 9:06am    
Please use code block... and also indicate which error you have.

C#
mydate3 = (mydate - mydate2).ToString(); // ToString returns a String.
mydate3 is a DateTime and you are trying to assign a String to it.
C#
if (x("Selected") + 1 == x("correct")
You might need to explicitly convert x("Selected") and x("correct") to ints. They are now objects.
C#
if (Convert.ToInt32(x("Selected")) + 1 == Convert.ToInt32(x("correct"))
 
Share this answer
 
v3
Index accessors in c# are between brackets and not parenthesis =>

if (Convert.ToInt32(x["Selected"]) + 1 == Convert.ToInt32(x["correct"])
 
Share this answer
 
Comments
2011999 5-Nov-11 13:58pm    
if (Convert.ToInt32(x["Selected"]) + 1 == Convert.ToInt32(x["correct"])

this also not working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900