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. Other Discussions
  3. The Weird and The Wonderful
  4. The beauty that is the default conversion...

The beauty that is the default conversion...

Scheduled Pinned Locked Moved The Weird and The Wonderful
database
9 Posts 7 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.
  • OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #1

    Ladies and Gentlemen! Direct, from the wonders of Q&A (no, names, no embarrassment - although it is most definately deserved):

    SqlDataAdapter dad = new SqlDataAdapter("Select * from esrdat where esrdat_date between '" + Convert.ToDateTime(dateTimePicker1.Value) + "' and '" + Convert.ToDateTime(dateTimePicker2.Value) + "'", con);

    Here, for your delectation we have: 1) Take a valid DateTime 2) Use a default conversion to a string 3) Convert it back to a DateTime 4) Then pass that (converted back to a string via another default conversion) to SQL But in the local format, rather than anything SQL is expecting, which is ISO format. Twice. And it's in Q&A because SQL doesn't like the date format it eventually gets passed... :sigh:

    Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    B L P R 4 Replies Last reply
    0
    • OriginalGriffO OriginalGriff

      Ladies and Gentlemen! Direct, from the wonders of Q&A (no, names, no embarrassment - although it is most definately deserved):

      SqlDataAdapter dad = new SqlDataAdapter("Select * from esrdat where esrdat_date between '" + Convert.ToDateTime(dateTimePicker1.Value) + "' and '" + Convert.ToDateTime(dateTimePicker2.Value) + "'", con);

      Here, for your delectation we have: 1) Take a valid DateTime 2) Use a default conversion to a string 3) Convert it back to a DateTime 4) Then pass that (converted back to a string via another default conversion) to SQL But in the local format, rather than anything SQL is expecting, which is ISO format. Twice. And it's in Q&A because SQL doesn't like the date format it eventually gets passed... :sigh:

      Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #2

      Where's the first conversion? Is dateTimePicker.Value not a DateTime? By the way I hope you answered the question as well as posting it here because that seems like newbie ignorance that deserves illumination.

      OriginalGriffO 1 Reply Last reply
      0
      • B BobJanova

        Where's the first conversion? Is dateTimePicker.Value not a DateTime? By the way I hope you answered the question as well as posting it here because that seems like newbie ignorance that deserves illumination.

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        You are right, I am wrong - somebody went to the work of adding a DateTime convertion routine that accepts a DateTime, and returns it, unchanged! :-O (I suspect I would have deliberately omitted it, or thrown an exception if you tried to use it, just for being silly) And yes I did.

        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Ladies and Gentlemen! Direct, from the wonders of Q&A (no, names, no embarrassment - although it is most definately deserved):

          SqlDataAdapter dad = new SqlDataAdapter("Select * from esrdat where esrdat_date between '" + Convert.ToDateTime(dateTimePicker1.Value) + "' and '" + Convert.ToDateTime(dateTimePicker2.Value) + "'", con);

          Here, for your delectation we have: 1) Take a valid DateTime 2) Use a default conversion to a string 3) Convert it back to a DateTime 4) Then pass that (converted back to a string via another default conversion) to SQL But in the local format, rather than anything SQL is expecting, which is ISO format. Twice. And it's in Q&A because SQL doesn't like the date format it eventually gets passed... :sigh:

          Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

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

          And let's add not using SQL parameters to avoid most of this to the list

          I'm invincible, I can't be vinced

          1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Ladies and Gentlemen! Direct, from the wonders of Q&A (no, names, no embarrassment - although it is most definately deserved):

            SqlDataAdapter dad = new SqlDataAdapter("Select * from esrdat where esrdat_date between '" + Convert.ToDateTime(dateTimePicker1.Value) + "' and '" + Convert.ToDateTime(dateTimePicker2.Value) + "'", con);

            Here, for your delectation we have: 1) Take a valid DateTime 2) Use a default conversion to a string 3) Convert it back to a DateTime 4) Then pass that (converted back to a string via another default conversion) to SQL But in the local format, rather than anything SQL is expecting, which is ISO format. Twice. And it's in Q&A because SQL doesn't like the date format it eventually gets passed... :sigh:

            Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

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

            See? That's one of the problems with giving newbies a "Convert" class; they think they need it all the frickin' time -- they don't learn what it does or what alternatives there are.

            L 1 Reply Last reply
            0
            • P PIEBALDconsult

              See? That's one of the problems with giving newbies a "Convert" class; they think they need it all the frickin' time -- they don't learn what it does or what alternatives there are.

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

              And that's what I always say: Let them learn with an old school single board computer. Take away all fancy frameworks and operating systems and let them discuss things directly with the processor for a while. By the time we give them any compilers, they will already have gotten used to using that grey mass in their heads for other things than keeping the ears apart.

              I'm invincible, I can't be vinced

              T G 2 Replies Last reply
              0
              • OriginalGriffO OriginalGriff

                Ladies and Gentlemen! Direct, from the wonders of Q&A (no, names, no embarrassment - although it is most definately deserved):

                SqlDataAdapter dad = new SqlDataAdapter("Select * from esrdat where esrdat_date between '" + Convert.ToDateTime(dateTimePicker1.Value) + "' and '" + Convert.ToDateTime(dateTimePicker2.Value) + "'", con);

                Here, for your delectation we have: 1) Take a valid DateTime 2) Use a default conversion to a string 3) Convert it back to a DateTime 4) Then pass that (converted back to a string via another default conversion) to SQL But in the local format, rather than anything SQL is expecting, which is ISO format. Twice. And it's in Q&A because SQL doesn't like the date format it eventually gets passed... :sigh:

                Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                R Offline
                R Offline
                RobCroll
                wrote on last edited by
                #7

                Making database queries in the presentation layer!! :wtf:

                "You get that on the big jobs."

                1 Reply Last reply
                0
                • L Lost User

                  And that's what I always say: Let them learn with an old school single board computer. Take away all fancy frameworks and operating systems and let them discuss things directly with the processor for a while. By the time we give them any compilers, they will already have gotten used to using that grey mass in their heads for other things than keeping the ears apart.

                  I'm invincible, I can't be vinced

                  T Offline
                  T Offline
                  tgrt
                  wrote on last edited by
                  #8

                  ...Or they run away screaming. win-win

                  1 Reply Last reply
                  0
                  • L Lost User

                    And that's what I always say: Let them learn with an old school single board computer. Take away all fancy frameworks and operating systems and let them discuss things directly with the processor for a while. By the time we give them any compilers, they will already have gotten used to using that grey mass in their heads for other things than keeping the ears apart.

                    I'm invincible, I can't be vinced

                    G Offline
                    G Offline
                    Gary Wheeler
                    wrote on last edited by
                    #9

                    In my experience, once you turn them into embedded programmers, they always think they have to roll their own. We've got a guy in our group like that. We're constantly having to tell him "No, just use class Mousetrap. Yes, yours is cool and all, but we've got lots of time on Mousetrap, plus it works with the rest of the architecture. No, yours doesn't."

                    Software Zen: delete this;

                    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