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. General Programming
  3. C#
  4. About dateTimePicker problem

About dateTimePicker problem

Scheduled Pinned Locked Moved C#
helpquestion
8 Posts 6 Posters 1 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
    miss YY
    wrote on last edited by
    #1

    string from,to; from=this.dateTimePicker1.Value.ToShortDateString(); to=this.dateTimePicker2.Value.ToShortDateString(); string str="select * from Furn_Info where Time between ‘"+from+"’ and ‘"+to+"’"; but it do not work as i think ,i'm use data SQl2000 please show me how can i do

    A L S 3 Replies Last reply
    0
    • M miss YY

      string from,to; from=this.dateTimePicker1.Value.ToShortDateString(); to=this.dateTimePicker2.Value.ToShortDateString(); string str="select * from Furn_Info where Time between ‘"+from+"’ and ‘"+to+"’"; but it do not work as i think ,i'm use data SQl2000 please show me how can i do

      A Offline
      A Offline
      avigodse
      wrote on last edited by
      #2

      Hi, there are many reasons behind not getting resultset. some of them can be your datepicker value is not in correct date format as SQL expects, or check your system date formats, or just format date value before adding to query.

      Avinash S. Godse

      Z 1 Reply Last reply
      0
      • M miss YY

        string from,to; from=this.dateTimePicker1.Value.ToShortDateString(); to=this.dateTimePicker2.Value.ToShortDateString(); string str="select * from Furn_Info where Time between ‘"+from+"’ and ‘"+to+"’"; but it do not work as i think ,i'm use data SQl2000 please show me how can i do

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

        Try this:

        from=this.dateTimePicker1.Value.ToString("yyyy/MM/dd");
        to=this.dateTimePicker2.Value.ToString("yyyy/MM/dd");

        1 Reply Last reply
        0
        • M miss YY

          string from,to; from=this.dateTimePicker1.Value.ToShortDateString(); to=this.dateTimePicker2.Value.ToShortDateString(); string str="select * from Furn_Info where Time between ‘"+from+"’ and ‘"+to+"’"; but it do not work as i think ,i'm use data SQl2000 please show me how can i do

          S Offline
          S Offline
          ScottM1
          wrote on last edited by
          #4

          miss YY wrote:

          string str="select * from Furn_Info where Time between ‘"+from+"’ and ‘"+to+"’";

          Rather parameterize your queries like so: cmd.CommandText = "select * from Furn_Info where Time between @from and @to"; cmd.Parameters.AddWithValue("@from", from.ToString("yyyyMMdd")); cmd.Parameters.AddWithValue("@to", to.ToString("yyyyMMdd"));

          P 1 Reply Last reply
          0
          • S ScottM1

            miss YY wrote:

            string str="select * from Furn_Info where Time between ‘"+from+"’ and ‘"+to+"’";

            Rather parameterize your queries like so: cmd.CommandText = "select * from Furn_Info where Time between @from and @to"; cmd.Parameters.AddWithValue("@from", from.ToString("yyyyMMdd")); cmd.Parameters.AddWithValue("@to", to.ToString("yyyyMMdd"));

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Yes parameterize, but don't make the dates into strings.

            S 1 Reply Last reply
            0
            • P PIEBALDconsult

              Yes parameterize, but don't make the dates into strings.

              S Offline
              S Offline
              ScottM1
              wrote on last edited by
              #6

              Why not? How would you do it, just put the DateTime object as the parameter value?

              P 1 Reply Last reply
              0
              • S ScottM1

                Why not? How would you do it, just put the DateTime object as the parameter value?

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                ScottM1 wrote:

                put the DateTime object as the parameter value?

                Of course.

                1 Reply Last reply
                0
                • A avigodse

                  Hi, there are many reasons behind not getting resultset. some of them can be your datepicker value is not in correct date format as SQL expects, or check your system date formats, or just format date value before adding to query.

                  Avinash S. Godse

                  Z Offline
                  Z Offline
                  zingoraa
                  wrote on last edited by
                  #8

                  Avinash, Same names. Yet you could have given this answer with example.

                  modified on Friday, April 8, 2011 11:14 AM

                  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