Click here to Skip to main content
15,919,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys,

After a bit of testing I bumped into wall again...
I am trying to start a program (MS Access) in different regional settings. I have tried to do it this way:
C#
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");

Access.Application AcApp = new Access.Application();
AcApp.OpenCurrentDatabase(@"C:\test.accdb");


So - my original regional settings of the system are German so date separator is dot "." and in "en-GB" it should be "/". Though when I open the DB with the code above I still see "." as date separator. (So it's 2013.04.04, while I want to see 2013/04/04)

Is anyone aware of what I doing wrong here?

P.S.: what I am trying to achieve here is make everyone to have the same view of the database table. No matter what regional settings they are using as default on their systems.

Thanks a lot m8s!
Posted

The first thing to say is: probably, you are making a mistake by trying to "fix" the culture to any format - particularly if it is one which can be confused. People set the culture on their PC to what they are used to, and fixing it to something else may cause problems or even anger. So unless this is for a very, very good reason, then don't do it.

If it is for a good reason, then it's pretty simple to do: I assume that you are using a DateTime value here, as string based dates don't change format! :laugh:

All you have to do is stop using the default transformation. Without knowning exactly what you are doing to display it, it's difficult to be precise about what you need to do, ybut at somepoint you are using the default ToString implementation, either explicitly or implicitly via a string concatenation. Instead, specify exactly what format you want:
C#
DateTime now = DateTime.Now;
string s = now.ToString("yyyy/MM/dd");

If the problem is that the dates in Access are being displayed in the local format, then changing the thread culture will not help - the Access instance will not share a common thread with your application because it is a separate Process, with it's own thread collection, so changing the culture will have no affect on it. And if you start mucking with the global culture you will really annoy your users!

It may be possible to format the date output for specific data in Access itself, depending on what you are using to display the info.
 
Share this answer
 
Comments
MK-Gii 4-Apr-13 7:32am    
Well - it's not string based. And the regional setting switch is not what I am trying to achieve. I just want everybody using the program to be tied to the view I am giving. You know - some users will copy/paste the date from the DB into mail and having mails with diferent date formats is not what I am looking for. The environment where I am working is multicultural so I want to set the standard for this. And yeah - I don't care about the fact that some people are using any other operators for date separation - we must have the same.

So - I still need to get this done.
Found the solution - I wrote the function which will read the registry key from here:
Computer\HKEY_CURRENT_USER\Control Panel\International\sDate
Computer\HKEY_CURRENT_USER\Control Panel\International\sShortDate
Store their values in some string variables.
Change the separator to whatever I need. This takes effect immediately (no need to relogin)
:)
Then I open the DB and user sees what I want.
When he closes the program - it restores the settings back.

This is so far the only solution I could think of.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900