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
  1. Home
  2. General Programming
  3. C#
  4. format date

format date

Scheduled Pinned Locked Moved C#
databasetutorialquestion
6 Posts 4 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.
  • B Offline
    B Offline
    balanjingot
    wrote on last edited by
    #1

    hi, how to insert the value of my datetimepicker to my database table? this is my code: private void button6_Click(object sender, EventArgs e) { try { string dateneeded = dateTimePicker6.Value.ToLongDateString(); String query = "INSERT INTO purchaserequest(dateneeded) VALUES (DATE_FORMAT(dateneeded,'%Y-%m-%d')"; MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); } catch (MySqlException mse) { MessageBox.Show(mse.Message); } } its not working:) thanks in advance:) regards:)

    jing

    P N M 3 Replies Last reply
    0
    • B balanjingot

      hi, how to insert the value of my datetimepicker to my database table? this is my code: private void button6_Click(object sender, EventArgs e) { try { string dateneeded = dateTimePicker6.Value.ToLongDateString(); String query = "INSERT INTO purchaserequest(dateneeded) VALUES (DATE_FORMAT(dateneeded,'%Y-%m-%d')"; MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); } catch (MySqlException mse) { MessageBox.Show(mse.Message); } } its not working:) thanks in advance:) regards:)

      jing

      P Offline
      P Offline
      phantanagu
      wrote on last edited by
      #2

      You should use Parameter to make it easier instead of formatting datetime. string dateneeded = dateTimePicker6.Value.ToLongDateString(); String query = "INSERT INTO purchaserequest(dateneeded) VALUES (?)"; MySqlCommand command = new MySqlCommand(query, connection); command.Parameters.Add(new MySqlParameter("pDate",dateneeded)); command.ExecuteNonQuery();

      It seem to be a solution or an answer.

      B 1 Reply Last reply
      0
      • P phantanagu

        You should use Parameter to make it easier instead of formatting datetime. string dateneeded = dateTimePicker6.Value.ToLongDateString(); String query = "INSERT INTO purchaserequest(dateneeded) VALUES (?)"; MySqlCommand command = new MySqlCommand(query, connection); command.Parameters.Add(new MySqlParameter("pDate",dateneeded)); command.ExecuteNonQuery();

        It seem to be a solution or an answer.

        B Offline
        B Offline
        balanjingot
        wrote on last edited by
        #3

        hi, thanks...il try this one... i appreciate it... regards:) ;)

        jing

        1 Reply Last reply
        0
        • B balanjingot

          hi, how to insert the value of my datetimepicker to my database table? this is my code: private void button6_Click(object sender, EventArgs e) { try { string dateneeded = dateTimePicker6.Value.ToLongDateString(); String query = "INSERT INTO purchaserequest(dateneeded) VALUES (DATE_FORMAT(dateneeded,'%Y-%m-%d')"; MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); } catch (MySqlException mse) { MessageBox.Show(mse.Message); } } its not working:) thanks in advance:) regards:)

          jing

          N Offline
          N Offline
          Nouman Bhatti
          wrote on last edited by
          #4

          you just have to use the datetimepicker properties/methods datetimepicker.value (one way to get the datetimepicker value)

          1 Reply Last reply
          0
          • B balanjingot

            hi, how to insert the value of my datetimepicker to my database table? this is my code: private void button6_Click(object sender, EventArgs e) { try { string dateneeded = dateTimePicker6.Value.ToLongDateString(); String query = "INSERT INTO purchaserequest(dateneeded) VALUES (DATE_FORMAT(dateneeded,'%Y-%m-%d')"; MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); } catch (MySqlException mse) { MessageBox.Show(mse.Message); } } its not working:) thanks in advance:) regards:)

            jing

            M Offline
            M Offline
            Manoj Kumar Rai
            wrote on last edited by
            #5

            jing, You can try an essy way out. Just put the "date-time" in single quote while preparing sql string. i.e. your query string should be changed as below: String query = "INSERT INTO purchaserequest(dateneeded) VALUES (" + "'" + dateneeded + "'" + )"; Also please check you have the correct column name. Manoj

            B 1 Reply Last reply
            0
            • M Manoj Kumar Rai

              jing, You can try an essy way out. Just put the "date-time" in single quote while preparing sql string. i.e. your query string should be changed as below: String query = "INSERT INTO purchaserequest(dateneeded) VALUES (" + "'" + dateneeded + "'" + )"; Also please check you have the correct column name. Manoj

              B Offline
              B Offline
              balanjingot
              wrote on last edited by
              #6

              thats it!! tnx!

              jing

              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