473,395 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DateTimePicker problem

Hi this is a strange problem which only occurs on one computer in our office.

I have a DateTimePicker in my C# application and it works properly on everyone's computer (except one) to select specific dates.

I noticed that on the one problem computer that when the DateTimePicker is used it sets the date a little different that on working computers.

His looks like this once he uses the calendar:
'February -14-12'

Mine looks like this:
'Tuesday , February 14,2012'

Once he selects a specific date the above shows up but an exception arises:
System.Data.SqlClient.SqlException: Conversion failed when converting date and/or time from character string.

This is the only code I can think of to submit:
Expand|Select|Wrap|Line Numbers
  1. dtpAppts.Value.ToShortDateString()
This is a C# Winform application running against a SQL DB. VS 2010 pro / Framework 3.5.

I understand the cast problem above but why wouldn't an else have the same problem? My thoughts point to a local system problem but he's using the same OS and setup as everyone else (Windows 7 pro with SP1).

I have a feeling it's not a problem with the C# coding but a problem with the querry, or how C# is interpreting it...or something like this. Strange though, only on one computer?

Does anyone have any thoughts?

Thanks very much,

~ Chris
Feb 14 '12 #1

✓ answered by GaryTexmo

Darn... that's usually the culprit. He's running an executable you built right, so it should work.

If you're able to, set up remote debugging and see if you can debug his application from your computer. Perhaps then you can set some breakpoints and find out what your datetimes are getting set to or even what the program thinks it's CurrentCulture setting is (in case it's telling the OS to take a hike and doing it's own magic).

Failing that, I'd suggest perhaps giving him a special debug build of your application that will output to a log file so you can get a better picture of what's happening behind the scenes.

6 3447
GaryTexmo
1,501 Expert 1GB
Did you check his region settings? If it's Win7, go to Control Panel and select Region and Language. Check to see if his date and time formats differ from yours.
Feb 15 '12 #2
I checked today and it was exactly the same as mine.
Good thought though.

Any other thoughts?

Thanks,

~ Chris
Feb 16 '12 #3
GaryTexmo
1,501 Expert 1GB
Darn... that's usually the culprit. He's running an executable you built right, so it should work.

If you're able to, set up remote debugging and see if you can debug his application from your computer. Perhaps then you can set some breakpoints and find out what your datetimes are getting set to or even what the program thinks it's CurrentCulture setting is (in case it's telling the OS to take a hike and doing it's own magic).

Failing that, I'd suggest perhaps giving him a special debug build of your application that will output to a log file so you can get a better picture of what's happening behind the scenes.
Feb 16 '12 #4
You actually had it correct.
Well I'm happy to say it’s fixed but somewhat embarrassed too…
I completely neglected to try to replicate the problem from my home machine ..a Win 7 machine.
Perhaps I should have also mentioned that … I'm in Canada!

The problem was that my colleague and I had our settings set to English (Canada).
While I compared my settings at home to my colleague I realized today that I actually never tried the DateTimePicker from home (it just never came up), I use it at work where I still use an XP system.

Thanks again for your input, I appreciate it but it does bring up one question:
Is there a way to get .net to no matter what date format or setting it is, convert it to a format the application uses (US English)?

This is the code I have:
and CAST(MyDate AS DATE) = CAST('" + dtpMyDates.Value.ToShortDateString() + "' as DATE)
dtpMyDates.Value.ToShortDateString() is the DatetimePicker .net part and everything else on the outside is MSSQL (the database I'm getting my dates from).

I'll try ToLongDateString() ....etc and post my results.

Thanks again,

~ Chris
Feb 16 '12 #5
GaryTexmo
1,501 Expert 1GB
Well, you can override the system culture settings if you want... I think it's Thread.CurrentThread.CurrentCulture, or something to that effect. You can change it. You can also specify a culture when you do DateTime conversions (or number format conversions for that matter).

That said, it's generally best if you let your program deal in the culture that the system is set to. As long as you're not crossing cultures you're ok... but it does sound like you are.

That code you posted... is that SQL? If so, the yea you might want to give the "en-US" culture format specifier when you convert it to a string, assuming you're going to make sure all your database entries are in the US date format.

One final thing... I notice you're using string concatenation for building your SQL string. This is pretty dangerous as it leaves your code open to SQL injection attacks. You should look into using parameterized queries instead. If any of that is confusing and you'd like more information, please feel free to post another topic to look into it, just so we can keep information organized around here :)
Feb 16 '12 #6
Sorry for the tardy reply, life keeps us really busy doesn't it?

Thanks for the input GaryTexmo I'll give the code a try when I get a chance.

Yes it's SQL. The app I'm working on is only available via the internal network and it's only accessable via secure, encrypted login. That said you do have a point and I will heed your advice. I'm a little new at coding like this and unfortunately there's no one to look over my shoulder to guide me and point me to proper coding...I guess that's what brings me here.

I'll be eventually setting this up as am intranet site and possible acessable via the web so I'll definitely have to do it properly then.

Thanks again,

~ Chris
Feb 23 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Billy Jacobs | last post by:
I have created a DataGridColumnDatePicker Component so that I can put a datetimepicker control in my datagrid. It almost works. When I put my mouse in the cell it changes to a datetimepicker...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
0
by: Sumit | last post by:
Hi all, I have a datetimepicker on my windows form. When the user selects it i check whether the date entered is a Sunday or not & if its not a sunday i want that the control remains on the...
4
by: Jacek Jurkowski | last post by:
.... the minimum date of DateTimePicker is 1753-01-01. How to make DateTime to do not show nothing in its text if this date is the value? I have a form with a field LastLogonDate. If user hasn't...
0
by: KC | last post by:
How can you capture an event from the dropdown calendar in a DateTimePicker? I want the date the user picks to be added to a listbox, but the only way I can think to do that now it to check the...
7
by: Clamara | last post by:
When adding a new record from my form, I pre-set my DateTimePicker's value to System.DateTime.Today Since the "Today" value is used most of the time, the user doesn't need to select a date from...
1
by: skhairnar | last post by:
Hi All, I am trying to write a validation rule for DateTimePicker, which will prevent user from selecting saturday or sunday as a value. For this I have added an event handler with following code:...
3
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
11
by: jessy | last post by:
Hi, I have a problem with my DateTimePicker javascript code which i downloaded , the problem is when i pick the date and the date appears in my Text Field and i click Submit the date which i picked...
0
by: priyamtheone | last post by:
Can anyone provide me with a code example of how to use a datetimepicker cell in datagridview where in the datetimepicker column i can set the value of any cell to null or to any datetime according...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.