String was not recognized as a valid DateTime

Posted by Mandlaa under ASP.NET on 6/13/2013 | Points: 10 | Views : 981 | Status : [Member] | Replies : 1
I am inserting date value to database,My table column datatype is date

SqlParameter validUntil = new SqlParameter("@ValidUntil", SqlDbType.Date);
//validUntil.Value = TextBox2.Text.ToString();
validUntil.Value = Convert.ToDateTime(TextBox2.Text.ToString());
At the time of inserting getting Error like this:::String was not recognized as a valid DateTime in


Posted by: Allemahesh on: 6/13/2013 [Member] [MVP] Silver | Points: 25

You can use this :
DateTime date = DateTime.ParseExact(TextBox2.Text.ToString(), "dd/MM/yyyy", null);
validUntil.Value = date;

Hope this will help you.

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response