0

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

Girish
  • 35
  • 1
  • 11

2 Answers2

0

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);
user854301
  • 5,383
  • 3
  • 28
  • 37
0

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?

Community
  • 1
  • 1
Konstantin Chernov
  • 1,899
  • 2
  • 21
  • 37