The beauty that is the default conversion...
-
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
-
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
-
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.
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
-
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
-
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
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.
-
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.
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
-
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
-
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
-
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
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 onMousetrap
, plus it works with the rest of the architecture. No, yours doesn't."Software Zen:
delete this;