C# .NET - String was not recognized as a valid DateTime.

Asked By Gunasundari Loganathan on 24-Sep-13 02:40 AM
Hi all,

i have a column named PODate of datatype Date in Sqlserver 2008 r2. I have to insert values to that. I have a textbox with calender Extender which is used to select date. When i used to insert in the table textbox1.text it shows
"String was not recognized as a valid DateTime." so i changed it to

convert.todatetime(Textbox1.text).ToString("yyyy-MM-dd") it worked correctly nearly for two months then shows the same error.

Then i changed it to

      DateTimeFormatInfo Quotedatef = new DateTimeFormatInfo();
            string Qdate = Txt_quotedatedom.Text;
            Quotedatef.ShortDatePattern = "dd-MM-yyyy";
            Quotedatef.DateSeparator = "-";
            DateTime Quotedate = Convert.ToDateTime(Qdate, Quotedatef);

it shows the same error after one month. So i want to know how to get only date from datetime . Advance thanks for all