PC Review


Reply
Thread Tools Rate Thread

DataRowCollection.Add and NumberDecimalSeparator

 
 
Vyacheslav Lanovets
Guest
Posts: n/a
 
      22nd Feb 2005
Hello, All!

I have a Column object with String DataType, so when it's assigned with
Double value it gets converted to String. Convertion uses default locale
which in my case has "," as NumberDecimalSeparator.
Assigning is perfomed by DataRowCollection.Add(object[])

I see two solutions:
- change current thread's Culture before calling Add() (I use this solution
now)
- change DataType of Column to double, so WriteXml of Dataset will write it
with neutral culture

Are there any other solutions? Somehow substitute neutral culture for
convertion?

My code:
------------
DataSet cnv_ds = new DataSet();
cnv_ds.ReadXmlSchema(m_convert_schema); // so all Columns are Strings
cnv_ds.Tables.Add("Converted");
foreach (DataRow row in xls_ds.Tables[0].Rows)
{
object[] ins_row = ConvertRow(row.ItemArray);
cnv_ds.Tables[0].Rows.Add(ins_row); // here I get 92,5 instead of 92.5
}
-------------

Best regards, Vyacheslav Lanovets


 
Reply With Quote
 
 
 
 
Ollie Riches
Guest
Posts: n/a
 
      22nd Feb 2005
why not change the Locale of the DataTable? check out DataTable.Locale


--
HTH

Ollie Riches
http://www.phoneanalyser.net

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a programmer
helping programmers.

"Vyacheslav Lanovets" <xentrax_umail_ru> wrote in message
news:(E-Mail Removed)...
> Hello, All!
>
> I have a Column object with String DataType, so when it's assigned with
> Double value it gets converted to String. Convertion uses default locale
> which in my case has "," as NumberDecimalSeparator.
> Assigning is perfomed by DataRowCollection.Add(object[])
>
> I see two solutions:
> - change current thread's Culture before calling Add() (I use this

solution
> now)
> - change DataType of Column to double, so WriteXml of Dataset will write

it
> with neutral culture
>
> Are there any other solutions? Somehow substitute neutral culture for
> convertion?
>
> My code:
> ------------
> DataSet cnv_ds = new DataSet();
> cnv_ds.ReadXmlSchema(m_convert_schema); // so all Columns are Strings
> cnv_ds.Tables.Add("Converted");
> foreach (DataRow row in xls_ds.Tables[0].Rows)
> {
> object[] ins_row = ConvertRow(row.ItemArray);
> cnv_ds.Tables[0].Rows.Add(ins_row); // here I get 92,5 instead of

92.5
> }
> -------------
>
> Best regards, Vyacheslav Lanovets
>
>



 
Reply With Quote
 
Vyacheslav Lanovets
Guest
Posts: n/a
 
      22nd Feb 2005
Hello, Ollie!
You wrote on Tue, 22 Feb 2005 11:38:34 -0000:

OR> why not change the Locale of the DataTable? check out DataTable.Locale

Maybe I am not right, but this code will output the same for any locale:

CultureInfo nc = new CultureInfo("");
nc.NumberFormat.NumberDecimalSeparator = ","; // comment this out

Thread.CurrentThread.CurrentCulture = nc; // I'm trying to avoid this

DataSet dataSet = new DataSet("DoubleTest");
DataTable dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn("double", typeof(String)));

dataTable.Locale = new CultureInfo("ru-RU"); // ","
DataRow dataRow = dataTable.NewRow();
dataRow["double"] = 1.5;
dataTable.Rows.Add(dataRow);

dataTable.Locale = new CultureInfo("en-US"); // "."
dataRow = dataTable.NewRow();
dataRow["double"] = 2.5;
dataTable.Rows.Add(dataRow);

dataSet.Tables.Add(dataTable);
dataSet.WriteXml(Console.Out);
Console.WriteLine();



Regards, Vyacheslav



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0]Index was outside the bounds of the array Roman Microsoft Dot NET Framework 2 31st Aug 2009 01:01 PM
currentCulture.NumberFormat.NumberDecimalSeparator arne.wiklund@intellifield.no Microsoft C# .NET 2 16th Aug 2006 04:22 PM
NumberDecimalSeparator =?Utf-8?B?S2V2ZW4gQ29yYXp6YQ==?= Microsoft Dot NET Compact Framework 1 3rd Dec 2005 01:28 PM
double.Parse ignores NumberDecimalSeparator Marco Microsoft C# .NET 1 17th Oct 2005 05:03 PM
Subclassing the DataRowCollection Paul Bowman Microsoft ADO .NET 1 9th Jan 2004 10:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:54 AM.