Try adding this line before the code that converts the data incorrectly:
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US")
If it does not work, show more details about your code that converts the data.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hallo,
I have lot of xml tables with decimal numbers and they are formatted according to english or with dot (.) . I have an another system which has German system or it works with comma ( , ). My program converts all my xml table to List of objects when it loads, When i open my program in German system the converted list does not contain any decimals because in german system it takes . as comma.
how do i prevent my xmls being translated to list with local settings or what is the right method to approach or solve the problem?
Thanks
Try adding this line before the code that converts the data incorrectly:
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US")
If it does not work, show more details about your code that converts the data.
HI @Hobbyist_programmer ,
In the XML-Schema spec a double/decimal data type needs to be represented with a dot.
Please check here for a possible solution: xml-deserialization-of-double-value-with-german-decimal-separator-in-c-sharp
Thanks Viorel, It worked .. but below is my code i use to convert my datatable to List of Objects.
Public ntI As Type = Type.GetType("System.Nullable`1[System.Int32]")
Public ntD As Type = Type.GetType("System.Nullable`1[System.Double]")
Private Function ConvertDataTable(Of T As New)(table As DataTable) As List(Of T)
Return New List(Of T)(table.AsEnumerable().Select(Function(row) GetItem(Of T)(row)))
End Function
Public Function GetItem(Of T As New)(row As DataRow) As T
Dim item As New T
Dim itemType = GetType(T)
For Each column As DataColumn In row.Table.Columns
Dim prop = itemType.GetProperty(column.ColumnName)
If prop IsNot Nothing Then
If prop.PropertyType.Equals(ntI) Then
prop.SetValue(item, If(row.IsNull(column), Nothing, Convert.ChangeType(row(column), ntI.GetGenericArguments()(0))))
ElseIf prop.PropertyType.Equals(ntD) Then
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US")
prop.SetValue(item, If(row.IsNull(column), Nothing, Convert.ChangeType(row(column), ntD.GetGenericArguments()(0))))
Else
prop.SetValue(item, If(row.IsNull(column), Nothing, Convert.ChangeType(row(column), prop.PropertyType)))
End If
End If
Next
Return item
End Function