Pregunta

There is MyDataSet myDataSet with MyTable with column string MyNumber (names changed). Then a row is added to the table (existing code):

decimal d = GetSum();
myDataSet.MyTable.AddMyTableRow(d.ToString("F2"));

Now I have to get that decimal number. But it throws FormatException when I try

decimal.Parse(myDataSet.MyTable[0].MyNumber);
// or
decimal.Parse(myDataSet.MyTable[0].MyNumber, CultureInfo.InvariantCulture);
//or
decimal.Parse(myDataSet.MyTable[0].MyNumber, CultureInfo.CurrentCulture)
//or
anything else..
¿Fue útil?

Solución 3

I solved this by creating additional decimal columns for these numbers.

Otros consejos

I had a similar issue a few days back. This however was with my ModelBinding in a MVC project. I had to overwrite the class responsible for binding decimal values to model variables.

Try to replace the full stop (.) with a comma(,)

I would guess that a FormatException suggests that you are not putting a string value into the Decimal.Parse method.

http://msdn.microsoft.com/en-us/library/cafs243z.aspx

The MSDN suggests that:

FormatException = s is not in the correct format.

From the looks you are accessing the column itself rather than the data contained in it.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top