Detailsview shows real numbers with commata: Error converting data type nvarchar to real!

  • Thread starter Curious Trigger
  • Start date
C

Curious Trigger

Hello,

if have an asp.net web page with a detailsview. This detailsview uses a
sqldatasource connecting to a sql server 2005 database with a select
statement simliar to this one:

SELECT warning_threshold, critical_threshold, weight FROM thresholds
UPDATE thresholds SET warning_threshold=@warning_threshold,
critical_threshold=@critical_threshold, weight =@weight
I also added insert and delete statements to this datasource.

The fields warning_threshold, critical_threshold and weight are of sql-type
real and contain figures between 0.00 and 1.00 (e.g 0.85).

In the gridview those figures are shown with commata (0,85) and if I try to
update the dataset I get thist error:

"Error converting data type nvarchar to real!"

How I can ensure that all real-numbers are shown with a decimal point
instead of a comma?
And how can I asure that the user can enter only decimal points too?

Thank you very much for any advice!

Yours,
Mathias
 
R

Rob MacFadyen

Mathias,

Formatting is controlled by the cultural settings. If you've set an explicit
UI culture, or indicated an auto culture, or the server's inherient culture
uses a "european" numeric formatting (eg. 999 999,99) then what you are
seeing is the expected behavior.

You could force the culture in the web.config file:
<configuration>
<system.web>
<globalization
requestencoding="utf-8"
responseencoding=" utf-8"
fileencoding=" utf-8"
culture="de-DE"
uiculture="en" />
</system.web>
</configuration>


On a per page basis you can specify the culture:

<%@ Page Culture="ja-JP" UICulture="ja" ResponseEncoding="utf-8"%>



And you can do it with code:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");


You can also fish out the name of the current culture:

Thread.CurrentThread.CurrentCulture.EnglishName


Does any of that help?

Regards,

Rob MacFadyen
 
C

Curious Trigger

Hi Rob,

thank you very much! I changed my web.config and that solved my problem.
I couldn't simply cut and paste your text, because in web.config you have to
pay attention to lower-case and upper-case letters and leading spaces (e.g.
"utf-8" instead of " utf-8").
So I adopted it like this:

<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
fileEncoding="utf-8"
culture="en-US"
uiCulture="en" />

Regards,
Mathias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top