title: How to store date from text box in SQL Server through C# ASP.net
body: <p>I am having trouble while storing date in sql server DB through C# asp.net, online</p>
  
  <p>I have used asp Text box and asp calender extender in ASP file to get date from user,</p>
  
  <pre><code> &lt;asp:TextBox runat="server" ID="txt_date"&gt;&lt;/asp:TextBox&gt;
  &lt;asp:CalendarExtender runat="server" ID="cal_date" TargetControlID="txt_date"&gt;&lt;/asp:CalendarExtender&gt;
  </code></pre>
  
  <p>code behind file is, assume connection and command are declared and initialized ,</p>
  
  <pre><code>mycom = new SqlCommand("insert into mytable(dtCol1) values('"+Convert.ToDateTime(txt_dob.Text).ToString("dd-MMM-yyyy") + "')", mycon);mycom.ExecuteNonQuery();
  </code></pre>
  
  <p>Problem is, when I select date less than 12 of any month it works perfect,
  but when date/day is  greater than 12 of any month it gives error,</p>
  
  <pre><code>Exception Details: System.FormatException: String was not recognized as a valid DateTime.
  </code></pre>
  
  <p>I have tried all combinations of .ToString("dd-MMM-yyyy")</p>
  
  <p>Please Help 
  thanks in advance</p>