473,810 Members | 3,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateTimePicker problem

6 New Member
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.Sql Client.SqlExcep tion: 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
6 3465
GaryTexmo
1,501 Recognized Expert Top Contributor
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
Chris Beharry
6 New Member
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 Recognized Expert Top Contributor
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
Chris Beharry
6 New Member
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.Valu e.ToShortDateSt ring() + "' as DATE)
dtpMyDates.Valu e.ToShortDateSt ring() is the DatetimePicker .net part and everything else on the outside is MSSQL (the database I'm getting my dates from).

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

Thanks again,

~ Chris
Feb 16 '12 #5
GaryTexmo
1,501 Recognized Expert Top Contributor
Well, you can override the system culture settings if you want... I think it's Thread.CurrentT hread.CurrentCu lture, 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
Chris Beharry
6 New Member
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
2040
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 control. I can then select a date which displays in the cell. When I leave the cell however I get the following error:
9
3976
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 will not set the value of the control and will leave the checked status of the checkbox to false when a user selects a new date. this works fine when using the control on a win2k machine but if we use it on a win XP box and call
0
2178
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 DateTimePicker & the DateTimePicker is displayed in its expaned form (i.e displaying the calendar). If i do a datetimepicker.focus(), then the focus goes to the datetimepicker but the user who is using it might ignore the focus as
4
5685
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 logon yet this date should be empty but when binding a property to the DateTimePicker value it always shows value parsed prom property which is 1753-01-01. How to make an "empty" or "not set" date bindable to a value property of DateTimePicker?
0
1127
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 ValueChanged event in the DateTimePicker. Problem with that is if the user chooses a new month the value displayed changes which causes that date to be added to the list. I only want that to happen if the user chooses a date.
7
6219
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 the DateTimePicker, since the default is shown. My problem is, if the user does not choose a value from the DateTimePicker (because using the default is good enough), then during database update, the date value is not saved to the database; while if...
1
7625
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: private void dtpStartDate_ValueChanged(object sender, System.EventArgs e) { System.DayOfWeek i = dtpStartDate.Value.DayOfWeek; if((i == System.DayOfWeek.Sunday) || (i == System.DayOfWeek.Saturday))
3
7528
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 on. It's a simple program that loads a control onto a form and binds "Foo" against a combobox ("SelectedItem") for it's "Bar" property and a datetimepicker ("Value") for it's "DateTime" property. The DateTimePicker.Visible value is set to...
11
5028
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 is not sent to the DB and instead the default value of the text field which is 00-00-0000 is Sent so what i need is to make the value i picked replace the value of the Text Field and i cant seem to get the Js code which i downloaded . i'm...
0
2297
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 to my choice. And the format of the datetimepicker cell should be dd MMM yyyy. I checked a lot of examples in the forums including articles by Nils Jonsson, Pham Minh Tri and Claudio Grazioli but none of them works when the DGV is databound. It works...
0
10379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.