title: DateTime.Parse Converting String to DateTime Format Equals to DateTime Field in Database
body: <p>I am trying to convert a date value of YYYY/MM/DD from a textbox to datetime, when the value is correct it is ok but when I tried to input an incorrect data to check with the database, the error return as String was not recognized as a valid DateTime.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>  protected void btnSubmit_Click(object sender, EventArgs e)
      {
          string format = "YYYY-MM-DD HH:MM:SS";
          DateTime birthday = DateTime.Parse(txtBday.Text);
          DataSet ds = new DataSet();
          ds = (newService.checkAccount());
          if (ds.Tables[0].Rows.Count &gt; 0)
          {
              foreach (DataRow dRow in ds.Tables[0].Rows)
              {
                  string accountNo = dRow["ACCTNO"].ToString();
                  DateTime birthDate = DateTime.Parse(dRow["DATEOFBIRTH"].ToString());
                  if (accountNo == txtAccountNo.Text.ToString() &amp;&amp; birthDate == birthday)
                  {
                      lblMessage.Text = "&lt;br&gt;Account Number Exist. You may now proceed with the registration&lt;br&gt;&lt;br&gt;";
                      HttpCookie lmsCookie = new HttpCookie("id");
                      lmsCookie.Value = txtAccountNo.Text;
                      Response.Cookies.Add(lmsCookie);
                      Response.Redirect("Step2.aspx");
                  }
                  else
                  {
                      Image2.Visible = false;
                      lblMessage.Text = "&lt;br&gt;Please check your information and try again." + "&lt;br&gt;Be sure you are entering the correct information.For further assistance, call (+632) 404-2790.&lt;br&gt;&lt;br&gt;";
                  }
              }
          }
      }
  </code></pre>
  
  <p>For example I will enter a data that will match in the database, the program will proceed otherwise if I am going to input a data that does not match with any of the existing records in the database, the program will triggers an error, String was not recognized as valid datetime.</p>