none
How to insert name of MONTH is SQL using DateTimePicker in C#

    Question

  • Hello to all,

    This is my first time to ask here, so please bear with me.

    I have a DateTimePicker that gets the Date of Birth of an Employee. In my SQL Table, I have 3 columns with varchar data types (Emp_Month, Emp_Day, Emp_Year). I was able to insert into these columns. But what I want is that instead of

    Emp_Month = 1 (for January for example), I want the value to be "January" to be stored in my Table.

    I changed the format of my DateTimePicker to Custom with format: "MMMM dd, yyyy". Following this logic I tried to get the Month Value and format it,    New_BDayDatetimePicker.Value.Month.ToString("MMMM") .

    The other DateTimePickers in my application are able to store the name of the month. 

    How can I do this? Is it because I separated the value of the picker into three columns?
    (I can't change the SQL table , because, it is part of the requirements

    Thank you very much.

    Tuesday, October 29, 2013 1:41 PM

Answers

  • You should call the ToString method on the DateTime object rather than the Month property of the DateTime object:

    New_BDayDatetimePicker.Value.ToString("MMMM")

    Another option to get the month name is to use the below method:

    Emp_Month = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(New_BDayDatetimePicker.Value.Month)

    Tuesday, October 29, 2013 2:00 PM