I have used AJAX CalendarExtender to TextBox control. I want the value (Date) from TextBox to my database table. How'd I used
command.Parameters.AddWithValue(..?..)
The value when I select from Calender is appearing as -
August 9, 2012
I have used AJAX CalendarExtender to TextBox control. I want the value (Date) from TextBox to my database table. How'd I used
command.Parameters.AddWithValue(..?..)
The value when I select from Calender is appearing as -
August 9, 2012
HAve you tried to parse string with date time value like
var date = DateTime.ParseExact("August 9, 2012", "MMMM d, yyyy", CultureInfo.InvariantCulture);
command.Parameters.AddWithValue("@dateParameterName", date);
I would suggest utilizing DateTime.TryParse()
, cause user can enter any value into your text box, even invalid. DateTime.ParseExact()
is appropriate only if you are sure that string is a valid datetime of exact format.
You can reader more about it and about System.Convert.ToDateTime()
method here
Any difference between DateTime.Parse and Convert.ToDateTime?