Click here to Skip to main content
15,867,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
protected void btnsub_Click(object sender, EventArgs e)
    {
        schedule ob= new schedule();
        ob.u_id = Convert.ToInt32(txt_id.Text);
        bool isSubjectDuplicate = obj.schedule.Any(schedule => schedule.u_id == ob.u_id);

        if (isSubjectDuplicate == true)
        {
            Label2.Text = "YOU ALREADY SCHEDULED YOUR EXAM DATE";
        }
        else
        {
          var res1 = DateTime.Today.ToString();

          var res = (from test in obj.schedule where test.date == res1 select test).FirstOrDefault();
          if (res != null)
          {
              ob.name = txt_name.Text;
              ob.date = txtdate.Text;
              obj.schedule.AddObject(ob);
          }
          else
          {
              Response.Redirect("");
          }
          Response.Redirect("start.aspx");
          obj.SaveChanges();
       }
    }


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 21-Jan-14 8:57am
v2

1 solution

One of two things is probably happening here...

If test.date is a DateTime:
You are comparing it to a string. DateTime.Today.ToString() is probably not returning the value you think it is (it probably includes a time). Debug and set a breakpoint at var res = and see what the value of res1 and date are.

If test.date is a string
Its probably in the format MM/dd/yyyy or something similar, and again, DateTime.Today.ToString() does not return by default in that format, it includes a time. You will need to specify the format in the ToString("MM/dd/yyyy") or something similar to get the date in the same format as test.date.

It all boils down to debugging. Set a breakpoint at the var res = and see what the value of res1 and test.date is. They need to both be DateTime or both need to be strings and in the same date format.
 
Share this answer
 

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

  Print Answers RSS


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