locked
Populating dropdown from Access DateTime Field RRS feed

  • Question

  • User2103299984 posted
    Hi I have a datetime field in an access database that stores the datetime as dd/mm/yyyy. What I want to be able to do is to read the date from the database, extract each part individually (i.e. have only the day stored in a variable, then the month in a seperate variable etc)and then to use these variables to pre-select these values in a dropdown field which is to be presented to the user. Is this possible? If anyone can help or link to some tutorials I would be very grateful Thanks and Regards Drew
    Thursday, March 12, 2009 6:18 AM

Answers

  • User-1360095595 posted

    Yes this is very possible.  You can use the DateTime struct to extract any part of the date you want (Day, Month, Year).  Once you have these values, you can set the selectedvalue of whatever dropdowns you have set up.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 12, 2009 8:33 AM
  • User-1739016376 posted

      string timefromdb = "10/10/2008";


                DateTime dt = DateTime.Parse(timefromdb);

                int day = dt.Day;
                int month = dt.Month;
                int year = dt.Year;

                DropDownList1.Items.Add(day.ToString());
                DropDownList2.Items.Add(month.ToString());
                DropDownList3.Items.Add(year.ToString());

     

    Aravind

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 12, 2009 8:40 AM
  • User2103299984 posted
    Thanks for all your responses. For those that need it. Here's how i solved the problem..... string date_read = DataReader["closing_date"].ToString(); DateTime dt = Convert.ToDateTime(date_read); int day = dt.Day; int month = dt.Month; int year = dt.Year; string str_day = day.ToString(); start_day.Items.FindByValue(str_day).Selected = true; string str_month = month.ToString(); start_month.Items.FindByValue(str_month).Selected = true; string str_year = year.ToString(); start_year.Items.FindByValue(str_year).Selected = true;
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 12, 2009 10:48 AM

All replies

  • User-1360095595 posted

    Yes this is very possible.  You can use the DateTime struct to extract any part of the date you want (Day, Month, Year).  Once you have these values, you can set the selectedvalue of whatever dropdowns you have set up.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 12, 2009 8:33 AM
  • User-1739016376 posted

      string timefromdb = "10/10/2008";


                DateTime dt = DateTime.Parse(timefromdb);

                int day = dt.Day;
                int month = dt.Month;
                int year = dt.Year;

                DropDownList1.Items.Add(day.ToString());
                DropDownList2.Items.Add(month.ToString());
                DropDownList3.Items.Add(year.ToString());

     

    Aravind

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 12, 2009 8:40 AM
  • User2103299984 posted
    Thanks for all your responses. For those that need it. Here's how i solved the problem..... string date_read = DataReader["closing_date"].ToString(); DateTime dt = Convert.ToDateTime(date_read); int day = dt.Day; int month = dt.Month; int year = dt.Year; string str_day = day.ToString(); start_day.Items.FindByValue(str_day).Selected = true; string str_month = month.ToString(); start_month.Items.FindByValue(str_month).Selected = true; string str_year = year.ToString(); start_year.Items.FindByValue(str_year).Selected = true;
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 12, 2009 10:48 AM