Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. startdate in dropdownlist

startdate in dropdownlist

Scheduled Pinned Locked Moved ASP.NET
databasehelptutorial
14 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    m dhu
    wrote on last edited by
    #1

    concatenated three dropdownlists values i inserted year month day into a column in sql table. how to retrieve that values seperately to that three ddls from sql table help plz... for inserting i used....

    string str = DropDownList5.SelectedItem.Value.ToString();
    string str1 = DropDownList6.SelectedItem.Value.ToString();
    string str2 = DropDownList7.SelectedItem.Value.ToString();
    string final = str1 + "-" + str + "-" + str2;

    cmd.Parameters.Add("@startdate", SqlDbType.SmallDateTime.ToString()).Value = final;

    A J 2 Replies Last reply
    0
    • M m dhu

      concatenated three dropdownlists values i inserted year month day into a column in sql table. how to retrieve that values seperately to that three ddls from sql table help plz... for inserting i used....

      string str = DropDownList5.SelectedItem.Value.ToString();
      string str1 = DropDownList6.SelectedItem.Value.ToString();
      string str2 = DropDownList7.SelectedItem.Value.ToString();
      string final = str1 + "-" + str + "-" + str2;

      cmd.Parameters.Add("@startdate", SqlDbType.SmallDateTime.ToString()).Value = final;

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      madhukk wrote:

      cmd.Parameters.Add("@startdate", SqlDbType.SmallDateTime.ToString()).Value = final;

      Try This .

      DateTime MyDateTime;
      MyDateTime = new DateTime();
      MyDateTime = DateTime.ParseExact(final , "yyyy-MM-dd",
      null);

      cmd.Parameters.Add("@startdate",MyDateTime );

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

      M 1 Reply Last reply
      0
      • M m dhu

        concatenated three dropdownlists values i inserted year month day into a column in sql table. how to retrieve that values seperately to that three ddls from sql table help plz... for inserting i used....

        string str = DropDownList5.SelectedItem.Value.ToString();
        string str1 = DropDownList6.SelectedItem.Value.ToString();
        string str2 = DropDownList7.SelectedItem.Value.ToString();
        string final = str1 + "-" + str + "-" + str2;

        cmd.Parameters.Add("@startdate", SqlDbType.SmallDateTime.ToString()).Value = final;

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        SELECT DAY(startDate) as day, MONTH(startDate) as month, YEAR(startDate) AS Year FROM YourTable

        L 1 Reply Last reply
        0
        • A Abhijit Jana

          madhukk wrote:

          cmd.Parameters.Add("@startdate", SqlDbType.SmallDateTime.ToString()).Value = final;

          Try This .

          DateTime MyDateTime;
          MyDateTime = new DateTime();
          MyDateTime = DateTime.ParseExact(final , "yyyy-MM-dd",
          null);

          cmd.Parameters.Add("@startdate",MyDateTime );

          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

          M Offline
          M Offline
          m dhu
          wrote on last edited by
          #4

          im able to insert it.. i want to retrieve startdate column and transfer to other page using session.. using datareader i stored that column in a string

          SqlDataReader dr = cmd.ExecuteReader();
          while (dr.Read())
          { Session["startdate"] = dr["startdate"];
          }

          in next page to tranfer the value if i write this

          DropDownList1.SelectedItem.Text= Session["startdate"].ToString();

          im getting complete date(10/20/2001) in DropDownList1.. but what i want is ddl1(10) ddl2(20) ddl3(2001) as i inserted...

          L A 2 Replies Last reply
          0
          • M m dhu

            im able to insert it.. i want to retrieve startdate column and transfer to other page using session.. using datareader i stored that column in a string

            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            { Session["startdate"] = dr["startdate"];
            }

            in next page to tranfer the value if i write this

            DropDownList1.SelectedItem.Text= Session["startdate"].ToString();

            im getting complete date(10/20/2001) in DropDownList1.. but what i want is ddl1(10) ddl2(20) ddl3(2001) as i inserted...

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            madhukk wrote:

            im getting complete date(10/20/2001) in DropDownList1..

            Which is exactly what you coded. If you want to separate the values across different drop downs then you need to separate the components of the date. Day to one, month to another, and year to the third. How complicated can this be?

            1 Reply Last reply
            0
            • M m dhu

              im able to insert it.. i want to retrieve startdate column and transfer to other page using session.. using datareader i stored that column in a string

              SqlDataReader dr = cmd.ExecuteReader();
              while (dr.Read())
              { Session["startdate"] = dr["startdate"];
              }

              in next page to tranfer the value if i write this

              DropDownList1.SelectedItem.Text= Session["startdate"].ToString();

              im getting complete date(10/20/2001) in DropDownList1.. but what i want is ddl1(10) ddl2(20) ddl3(2001) as i inserted...

              A Offline
              A Offline
              Abhijit Jana
              wrote on last edited by
              #6

              You need to split them before store. :)

              Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

              M 1 Reply Last reply
              0
              • A Abhijit Jana

                You need to split them before store. :)

                Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                M Offline
                M Offline
                m dhu
                wrote on last edited by
                #7

                thats what im unable to any sample code please..

                A 1 Reply Last reply
                0
                • M m dhu

                  thats what im unable to any sample code please..

                  A Offline
                  A Offline
                  Abhijit Jana
                  wrote on last edited by
                  #8

                  madhukk wrote:

                  any sample code please..

                  One sample code for you.

                  String DateText="12/10/2009";
                  String [] DatePart= DateText.Split('/');
                  string dd=DatePart[0].ToString();
                  string mm=DatePart[1].ToString();
                  string yy=DatePart[2].ToString();

                  Hope you can take it forward. Let me know if any more issue.

                  Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                  N M 2 Replies Last reply
                  0
                  • A Abhijit Jana

                    madhukk wrote:

                    any sample code please..

                    One sample code for you.

                    String DateText="12/10/2009";
                    String [] DatePart= DateText.Split('/');
                    string dd=DatePart[0].ToString();
                    string mm=DatePart[1].ToString();
                    string yy=DatePart[2].ToString();

                    Hope you can take it forward. Let me know if any more issue.

                    Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                    N Offline
                    N Offline
                    Nisha Agrawal
                    wrote on last edited by
                    #9

                    I would prefer this one as it does not believe on string manipulatio and when we have datetime datatype then why do string manipulation?

                    String strDate = "12/27/2009"; //or any date format
                    String strFormat = "mm/dd/yyyy";
                    System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;
                    DateTime dt = DateTime.ParseExact(strDate, strFormat, provider);
                    String dd = dt.Day.ToString();
                    String mm = dt.Month.ToString();
                    String yyyy = dt.Year.ToString();

                    A L 2 Replies Last reply
                    0
                    • N Nisha Agrawal

                      I would prefer this one as it does not believe on string manipulatio and when we have datetime datatype then why do string manipulation?

                      String strDate = "12/27/2009"; //or any date format
                      String strFormat = "mm/dd/yyyy";
                      System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;
                      DateTime dt = DateTime.ParseExact(strDate, strFormat, provider);
                      String dd = dt.Day.ToString();
                      String mm = dt.Month.ToString();
                      String yyyy = dt.Year.ToString();

                      A Offline
                      A Offline
                      Abhijit Jana
                      wrote on last edited by
                      #10

                      Yes Nish, You are Correct. Actually there are many ways that we can implement it. I have given a very basic example. You given much better!:thumbsup: Thanks !

                      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                      1 Reply Last reply
                      0
                      • A Abhijit Jana

                        madhukk wrote:

                        any sample code please..

                        One sample code for you.

                        String DateText="12/10/2009";
                        String [] DatePart= DateText.Split('/');
                        string dd=DatePart[0].ToString();
                        string mm=DatePart[1].ToString();
                        string yy=DatePart[2].ToString();

                        Hope you can take it forward. Let me know if any more issue.

                        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                        M Offline
                        M Offline
                        m dhu
                        wrote on last edited by
                        #11

                        Session["headline"] = dr["headline"];
                        Session["startdate"] = dr["startdate"];
                        Response.Redirect("newsedit.aspx");

                        next page

                        TextBox5.Text = Session["headline"].ToString();
                        String DateText = Session["startdate"].ToString();
                        String[] DatePart = DateText.Split('/');
                        string dd = DatePart[0].ToString();
                        string mm = DatePart[1].ToString();
                        string yy = DatePart[2].ToString();
                        DropDownList6.SelectedItem.Text=dd.ToString();
                        Object reference not set to an instance of an object.

                        A 1 Reply Last reply
                        0
                        • M m dhu

                          Session["headline"] = dr["headline"];
                          Session["startdate"] = dr["startdate"];
                          Response.Redirect("newsedit.aspx");

                          next page

                          TextBox5.Text = Session["headline"].ToString();
                          String DateText = Session["startdate"].ToString();
                          String[] DatePart = DateText.Split('/');
                          string dd = DatePart[0].ToString();
                          string mm = DatePart[1].ToString();
                          string yy = DatePart[2].ToString();
                          DropDownList6.SelectedItem.Text=dd.ToString();
                          Object reference not set to an instance of an object.

                          A Offline
                          A Offline
                          Abhijit Jana
                          wrote on last edited by
                          #12

                          madhukk wrote:

                          Session["headline"] = dr["headline"]; Session["startdate"] = dr["startdate"]; Response.Redirect("newsedit.aspx"); next page TextBox5.Text = Session["headline"].ToString(); String DateText = Session["startdate"].ToString(); String[] DatePart = DateText.Split('/'); string dd = DatePart[0].ToString(); string mm = DatePart[1].ToString(); string yy = DatePart[2].ToString(); DropDownList6.SelectedItem.Text=dd.ToString(); Object reference not set to an instance of an object.

                          What is ur question ?

                          madhukk wrote:

                          DropDownList6.SelectedItem.Text=dd.ToString(); Object reference not set to an instance of an object.

                          I guess this one. What is the value of dd.ToString(); ? Does this exist on the dropdownlist? Hope now you understand what I want to mean ;)

                          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                          1 Reply Last reply
                          0
                          • J J4amieC

                            SELECT DAY(startDate) as day, MONTH(startDate) as month, YEAR(startDate) AS Year FROM YourTable

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #13

                            J4amieC wrote:

                            SELECT DAY(startDate) as day, MONTH(startDate) as month, YEAR(startDate) AS Year FROM YourTable

                            No, no, no! That's MUCH too sensible ... :laugh:

                            1 Reply Last reply
                            0
                            • N Nisha Agrawal

                              I would prefer this one as it does not believe on string manipulatio and when we have datetime datatype then why do string manipulation?

                              String strDate = "12/27/2009"; //or any date format
                              String strFormat = "mm/dd/yyyy";
                              System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;
                              DateTime dt = DateTime.ParseExact(strDate, strFormat, provider);
                              String dd = dt.Day.ToString();
                              String mm = dt.Month.ToString();
                              String yyyy = dt.Year.ToString();

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #14

                              If everybody stored their datetime values properly as DateTime values and not as strings they would not get into this mess. Who is teaching all these awful habits?

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups