0

We busy running c# asp website with MS SQL DB.

Some of the columns have been assigned type decimal(18,2).

SqlCommand cmd = new SqlCommand("select * from TABLE", conn);
SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())
{
    Response.Write("Amount : " + dr["DEC_COLUMN"].ToString());
}

On my colleagues localhost, when he does a simply select, values come back as 10.01 10.02 15.03 On my localhost it comes back as 10,01 10,02 15,03

My colleague and our Dev Server has the same values. Apart from the string replace hacks, I would like to get my settings the same so that my values also return with point not comma.

I checked the regional settings on my PC and its the exact same as the Dev server. I dumped my local DB and used the Export / Import wizard from Dev server but still no luck.

Which setting in windows / .NET / SQL is needed to be changed to make my local environment the same?

Shaakir
  • 464
  • 5
  • 13
  • 2
    What *exactly* do you mean by "values come back"? My guess is that you're getting the right `decimal` values from the server, but you're just displaying them according to local culture - in which case you really need to understand that a text format is *not* part of what's represented in a `decimal`. – Jon Skeet Mar 07 '16 at 15:23
  • Are you running the same executable. Try using exact same executable on both PC's. this way you can isolate the issue to the PC settings or the build settings. – jdweng Mar 07 '16 at 15:28
  • @Jon i have added the "values come back" code i'm referring to. THe Response.Write part is what i am referring to. Wehn viewing the same data in MS Man Studio, i see the point as well. SO you maybe onto something about my local culture. But since my copy of source code is the same as my colleages as well as that of dev server, all controlled by SVN, how could it differ? – Shaakir Mar 07 '16 at 15:30

1 Answers1

5

But since my copy of source code is the same as my colleages as well as that of dev server, all controlled by SVN, how could it differ?

Because the default system culture isn't defined in the source code.

I very much doubt that you really want to write a response in exactly that format anyway, but you could always specify the invariant culture:

while (dr.Read())
{
    decimal value = (decimal) dr["DEC_COLUMN"];
    Response.Write("Amount : " + value.ToString(CultureInfo.InvariantCulture));
}
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thank Jon.. You put me on the right track. The code snippet above was just to try and pinpoint the bigger problem we were having of my localhost having problems inserting updated into the DB. When user calls record from DB, it's put in a form and user submits, colleagues localhost, Dev Server works. In the form values all show ".". but Mine shows "," I just did this on the test page with simple select above and it worked. http://stackoverflow.com/questions/24785689/trying-to-set-the-decimal-separator-for-the-current-language-getting-instance/24785761 – Shaakir Mar 07 '16 at 15:48
  • what i did was also do this on my localhost, which solved the problem for my entire project. see answer from scott_lotus. http://stackoverflow.com/questions/9132720/server-set-to-en-gb-in-regional-settings-but-datetime-parsing-as-en-us – Shaakir Mar 08 '16 at 06:57
  • @Shaakir: That's a very brittle way of fixing the problem, in my view. I think it's a much better idea to simply make the code reflect what you want in terms of culture: where you want to use the end user's culture, make sure you do so. Why you want to use some other culture (e.g. the invariant culture), do that explicitly too. This is the same approach you should take to time zones, character encodings etc. Be explicit about everything, and your code will be clearer and won't need specific server setup. – Jon Skeet Mar 08 '16 at 06:58